2
2
mirror of https://github.com/octoleo/restic.git synced 2024-05-30 15:40:50 +00:00
restic/src/restic/find.go

38 lines
836 B
Go
Raw Normal View History

2016-08-01 16:31:44 +00:00
package restic
2016-08-15 15:58:32 +00:00
// 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.
2016-08-31 18:58:57 +00:00
func FindUsedBlobs(repo Repository, treeID ID, blobs BlobSet, seen BlobSet) error {
blobs.Insert(BlobHandle{ID: treeID, Type: TreeBlob})
2016-08-01 16:40:08 +00:00
tree, err := repo.LoadTree(treeID)
2016-08-01 16:40:08 +00:00
if err != nil {
return err
}
for _, node := range tree.Nodes {
2016-09-01 19:20:03 +00:00
switch node.Type {
2016-08-01 16:40:08 +00:00
case "file":
for _, blob := range node.Content {
2016-08-31 18:58:57 +00:00
blobs.Insert(BlobHandle{ID: blob, Type: DataBlob})
2016-08-01 16:40:08 +00:00
}
case "dir":
2016-08-01 16:45:03 +00:00
subtreeID := *node.Subtree
2016-08-31 18:58:57 +00:00
h := BlobHandle{ID: subtreeID, Type: TreeBlob}
if seen.Has(h) {
2016-08-01 16:45:03 +00:00
continue
}
seen.Insert(h)
2016-08-01 16:45:03 +00:00
2016-08-15 15:58:32 +00:00
err := FindUsedBlobs(repo, subtreeID, blobs, seen)
2016-08-01 16:40:08 +00:00
if err != nil {
return err
}
}
}
return nil
}