diff --git a/src/restic/find.go b/src/restic/find.go index 7d7a8698a..974ebf673 100644 --- a/src/restic/find.go +++ b/src/restic/find.go @@ -6,7 +6,7 @@ import ( ) // FindUsedBlobs traverse the tree ID and adds all seen blobs to blobs. -func findUsedBlobs(repo *repository.Repository, treeID backend.ID, blobs backend.IDSet) error { +func findUsedBlobs(repo *repository.Repository, treeID backend.ID, blobs backend.IDSet, seen backend.IDSet) error { blobs.Insert(treeID) tree, err := LoadTree(repo, treeID) @@ -21,7 +21,14 @@ func findUsedBlobs(repo *repository.Repository, treeID backend.ID, blobs backend blobs.Insert(blob) } case "dir": - err := findUsedBlobs(repo, *node.Subtree, blobs) + subtreeID := *node.Subtree + if seen.Has(subtreeID) { + continue + } + + seen.Insert(subtreeID) + + err := findUsedBlobs(repo, subtreeID, blobs, seen) if err != nil { return err } @@ -35,5 +42,5 @@ func findUsedBlobs(repo *repository.Repository, treeID backend.ID, blobs backend // encountered. func FindUsedBlobs(repo *repository.Repository, treeID backend.ID) (blobs backend.IDSet, err error) { blobs = backend.NewIDSet() - return blobs, findUsedBlobs(repo, treeID, blobs) + return blobs, findUsedBlobs(repo, treeID, blobs, backend.NewIDSet()) }