mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
Prevent loops when finding used blobs
This commit is contained in:
parent
ffc3503e6f
commit
bdd085e9f1
@ -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())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user