forked from TrueCloudLab/restic
parent
e77d8c64a7
commit
e085713b35
1 changed files with 10 additions and 2 deletions
|
@ -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) {
|
||||
checked := 0
|
||||
|
||||
// try at most maxKeysForSearch keys in repo
|
||||
err = s.Backend().List(ctx, restic.KeyFile, func(fi restic.FileInfo) error {
|
||||
listCtx, cancel := context.WithCancel(ctx)
|
||||
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 {
|
||||
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)
|
||||
k = key
|
||||
cancel()
|
||||
return nil
|
||||
})
|
||||
|
||||
if err == context.Canceled {
|
||||
err = nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue