lock after first return

This commit is contained in:
Aaron Bieber 2023-10-07 06:09:47 -06:00
parent 775c2dbb51
commit 26dde4e77f
No known key found for this signature in database

View File

@ -352,13 +352,13 @@ func (t *Traygent) Resize() {
func (t *Traygent) Add(key agent.AddedKey) error { func (t *Traygent) Add(key agent.AddedKey) error {
fmt.Println("Add") fmt.Println("Add")
t.mu.Lock()
signer, err := ssh.NewSignerFromKey(key.PrivateKey) signer, err := ssh.NewSignerFromKey(key.PrivateKey)
if err != nil { if err != nil {
return err return err
} }
t.mu.Lock()
p := NewPrivKey(signer, key) p := NewPrivKey(signer, key)
t.keys = append(t.keys, p) t.keys = append(t.keys, p)
@ -372,12 +372,12 @@ func (t *Traygent) Add(key agent.AddedKey) error {
func (t *Traygent) RemoveAll() error { func (t *Traygent) RemoveAll() error {
fmt.Println("RemoveAll") fmt.Println("RemoveAll")
t.mu.Lock()
if t.locked { if t.locked {
return errLocked return errLocked
} }
t.mu.Lock()
t.keys = nil t.keys = nil
t.log("All keys removed", "removed all keys from agent") t.log("All keys removed", "removed all keys from agent")
@ -390,18 +390,17 @@ func (t *Traygent) RemoveAll() error {
func (t *Traygent) Remove(key ssh.PublicKey) error { func (t *Traygent) Remove(key ssh.PublicKey) error {
fmt.Println("Remove") fmt.Println("Remove")
t.mu.Lock()
if t.locked { if t.locked {
return errLocked return errLocked
} }
t.mu.Lock()
err := t.remove(key) err := t.remove(key)
t.log("Key removed", "remove key from agent") t.log("Key removed", "remove key from agent")
t.mu.Unlock() t.mu.Unlock()
t.Resize() t.Resize()
return err return err