2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-09 23:00:57 +00:00
restic/internal/find.go
Alexander Neumann 83d1a46526 Moves files
2017-07-23 14:19:13 +02:00

40 lines
885 B
Go

package restic
import "context"
// FindUsedBlobs traverses the tree ID and adds all seen blobs (trees and data
// blobs) to the set blobs. The tree blobs in the `seen` BlobSet will not be visited
// again.
func FindUsedBlobs(ctx context.Context, repo Repository, treeID ID, blobs BlobSet, seen BlobSet) error {
blobs.Insert(BlobHandle{ID: treeID, Type: TreeBlob})
tree, err := repo.LoadTree(ctx, treeID)
if err != nil {
return err
}
for _, node := range tree.Nodes {
switch node.Type {
case "file":
for _, blob := range node.Content {
blobs.Insert(BlobHandle{ID: blob, Type: DataBlob})
}
case "dir":
subtreeID := *node.Subtree
h := BlobHandle{ID: subtreeID, Type: TreeBlob}
if seen.Has(h) {
continue
}
seen.Insert(h)
err := FindUsedBlobs(ctx, repo, subtreeID, blobs, seen)
if err != nil {
return err
}
}
}
return nil
}