github.com/mckael/restic@v0.8.3/internal/restic/find.go (about) 1 package restic 2 3 import "context" 4 5 // FindUsedBlobs traverses the tree ID and adds all seen blobs (trees and data 6 // blobs) to the set blobs. The tree blobs in the `seen` BlobSet will not be visited 7 // again. 8 func FindUsedBlobs(ctx context.Context, repo Repository, treeID ID, blobs BlobSet, seen BlobSet) error { 9 blobs.Insert(BlobHandle{ID: treeID, Type: TreeBlob}) 10 11 tree, err := repo.LoadTree(ctx, treeID) 12 if err != nil { 13 return err 14 } 15 16 for _, node := range tree.Nodes { 17 switch node.Type { 18 case "file": 19 for _, blob := range node.Content { 20 blobs.Insert(BlobHandle{ID: blob, Type: DataBlob}) 21 } 22 case "dir": 23 subtreeID := *node.Subtree 24 h := BlobHandle{ID: subtreeID, Type: TreeBlob} 25 if seen.Has(h) { 26 continue 27 } 28 29 seen.Insert(h) 30 31 err := FindUsedBlobs(ctx, repo, subtreeID, blobs, seen) 32 if err != nil { 33 return err 34 } 35 } 36 } 37 38 return nil 39 }