forked from TrueCloudLab/restic
find: Check trees only once
This commit is contained in:
parent
7b5efaf7b0
commit
a90e0c6595
1 changed files with 19 additions and 6 deletions
|
@ -176,9 +176,15 @@ type Finder struct {
|
|||
repo restic.Repository
|
||||
pat findPattern
|
||||
out statefulOutput
|
||||
notfound restic.IDSet
|
||||
}
|
||||
|
||||
func (f *Finder) findInTree(treeID restic.ID, prefix string) error {
|
||||
if f.notfound.Has(treeID) {
|
||||
debug.Log("%v skipping tree %v, has already been checked", prefix, treeID.Str())
|
||||
return nil
|
||||
}
|
||||
|
||||
debug.Log("%v checking tree %v\n", prefix, treeID.Str())
|
||||
|
||||
tree, err := f.repo.LoadTree(treeID)
|
||||
|
@ -186,6 +192,7 @@ func (f *Finder) findInTree(treeID restic.ID, prefix string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
var found bool
|
||||
for _, node := range tree.Nodes {
|
||||
debug.Log(" testing entry %q\n", node.Name)
|
||||
|
||||
|
@ -211,6 +218,7 @@ func (f *Finder) findInTree(treeID restic.ID, prefix string) error {
|
|||
}
|
||||
|
||||
debug.Log(" found match\n")
|
||||
found = true
|
||||
f.out.Print(prefix, node)
|
||||
}
|
||||
|
||||
|
@ -221,6 +229,10 @@ func (f *Finder) findInTree(treeID restic.ID, prefix string) error {
|
|||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
f.notfound.Insert(treeID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -282,6 +294,7 @@ func runFind(opts FindOptions, gopts GlobalOptions, args []string) error {
|
|||
repo: repo,
|
||||
pat: pat,
|
||||
out: statefulOutput{ListLong: opts.ListLong, JSON: globalOptions.JSON},
|
||||
notfound: restic.NewIDSet(),
|
||||
}
|
||||
for sn := range FindFilteredSnapshots(ctx, repo, opts.Host, opts.Tags, opts.Paths, opts.Snapshots) {
|
||||
if err = f.findInSnapshot(sn); err != nil {
|
||||
|
|
Loading…
Reference in a new issue