mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 14:56:29 +00:00
Merge pull request #1668 from restic/fix-1663
Return the first password/key which works
This commit is contained in:
commit
817890794d
@ -115,8 +115,11 @@ func OpenKey(ctx context.Context, s *Repository, name string, password string) (
|
|||||||
func SearchKey(ctx context.Context, s *Repository, password string, maxKeys int) (k *Key, err error) {
|
func SearchKey(ctx context.Context, s *Repository, password string, maxKeys int) (k *Key, err error) {
|
||||||
checked := 0
|
checked := 0
|
||||||
|
|
||||||
// try at most maxKeysForSearch keys in repo
|
listCtx, cancel := context.WithCancel(ctx)
|
||||||
err = s.Backend().List(ctx, restic.KeyFile, func(fi restic.FileInfo) error {
|
defer cancel()
|
||||||
|
|
||||||
|
// try at most maxKeys keys in repo
|
||||||
|
err = s.Backend().List(listCtx, restic.KeyFile, func(fi restic.FileInfo) error {
|
||||||
if maxKeys > 0 && checked > maxKeys {
|
if maxKeys > 0 && checked > maxKeys {
|
||||||
return ErrMaxKeysReached
|
return ErrMaxKeysReached
|
||||||
}
|
}
|
||||||
@ -142,9 +145,14 @@ func SearchKey(ctx context.Context, s *Repository, password string, maxKeys int)
|
|||||||
|
|
||||||
debug.Log("successfully opened key %v", fi.Name)
|
debug.Log("successfully opened key %v", fi.Name)
|
||||||
k = key
|
k = key
|
||||||
|
cancel()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err == context.Canceled {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user