2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-17 02:25:12 +00:00

Prevent loops when finding used blobs

This commit is contained in:
Alexander Neumann 2016-08-01 18:45:03 +02:00
parent ffc3503e6f
commit bdd085e9f1

View File

@ -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())
}