mirror of
https://github.com/restic/restic.git
synced 2026-05-21 17:45:23 +00:00
find: use proper sentinel error to terminate search
This commit is contained in:
@@ -22,6 +22,9 @@ import (
|
||||
"github.com/restic/restic/internal/walker"
|
||||
)
|
||||
|
||||
// errFindDone is returned from the tree walk when all requested tree IDs were found.
|
||||
var errFindDone = errors.New("find: all tree IDs found")
|
||||
|
||||
func newFindCommand(globalOptions *global.Options) *cobra.Command {
|
||||
var opts FindOptions
|
||||
|
||||
@@ -375,7 +378,7 @@ func (f *Finder) findTree(treeID restic.ID, nodepath string) error {
|
||||
// looking for blobs)
|
||||
if f.itemsFound >= len(f.treeIDs) && f.blobIDs == nil {
|
||||
// Return an error to terminate the Walk
|
||||
return errors.New("OK")
|
||||
return errFindDone
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -688,7 +691,7 @@ func runFind(ctx context.Context, opts FindOptions, gopts global.Options, args [
|
||||
|
||||
for _, sn := range filteredSnapshots {
|
||||
if f.blobIDs != nil || f.treeIDs != nil {
|
||||
if err = f.findIDs(ctx, sn); err != nil && err.Error() != "OK" {
|
||||
if err = f.findIDs(ctx, sn); err != nil && !errors.Is(err, errFindDone) {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user