From febdb8b564a15123b878e97eeec4ecf494311e12 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 16 May 2026 15:35:06 +0200 Subject: [PATCH] find: use proper sentinel error to terminate search --- cmd/restic/cmd_find.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index ae7782f85..8709a414d 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -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