mirror of
https://github.com/restic/restic.git
synced 2026-11-27 15:23:48 +00:00
Moves files
This commit is contained in:
1 parent
d1bd160b0a
commit
83d1a46526
284 files changed
No files matched your search
@@ -0,0 +1,39 @@
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user