2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 11:28:54 +00:00

Export FindUsedBlobs

This commit is contained in:
Alexander Neumann 2016-08-15 17:58:32 +02:00
parent 2b1b6d8c2a
commit d7e5f11b78
2 changed files with 9 additions and 12 deletions

View File

@ -6,8 +6,10 @@ import (
"restic/repository" "restic/repository"
) )
// findUsedBlobs traverse the tree ID and adds all seen blobs to blobs. // FindUsedBlobs traverses the tree ID and adds all seen blobs (trees and data
func findUsedBlobs(repo *repository.Repository, treeID backend.ID, blobs pack.BlobSet, seen pack.BlobSet) error { // blobs) to the set blobs. The tree blobs in the `seen` BlobSet will not be visited
// again.
func FindUsedBlobs(repo *repository.Repository, treeID backend.ID, blobs pack.BlobSet, seen pack.BlobSet) error {
blobs.Insert(pack.Handle{ID: treeID, Type: pack.Tree}) blobs.Insert(pack.Handle{ID: treeID, Type: pack.Tree})
tree, err := LoadTree(repo, treeID) tree, err := LoadTree(repo, treeID)
@ -30,7 +32,7 @@ func findUsedBlobs(repo *repository.Repository, treeID backend.ID, blobs pack.Bl
seen.Insert(h) seen.Insert(h)
err := findUsedBlobs(repo, subtreeID, blobs, seen) err := FindUsedBlobs(repo, subtreeID, blobs, seen)
if err != nil { if err != nil {
return err return err
} }
@ -39,8 +41,3 @@ func findUsedBlobs(repo *repository.Repository, treeID backend.ID, blobs pack.Bl
return nil return nil
} }
// FindUsedBlobs traverses the tree ID and adds all seen blobs (trees and data blobs) to the set blobs.
func FindUsedBlobs(repo *repository.Repository, treeID backend.ID, blobs pack.BlobSet) error {
return findUsedBlobs(repo, treeID, blobs, pack.NewBlobSet())
}

View File

@ -11,8 +11,8 @@ import (
const rebuildIndexWorkers = 10 const rebuildIndexWorkers = 10
// LoadBlobsResult is returned in the channel from LoadBlobsFromAllPacks. // ListAllPacksResult is returned in the channel from LoadBlobsFromAllPacks.
type LoadBlobsResult struct { type ListAllPacksResult struct {
PackID backend.ID PackID backend.ID
Entries []pack.Blob Entries []pack.Blob
} }
@ -22,7 +22,7 @@ func ListAllPacks(repo *Repository, ch chan<- worker.Job, done <-chan struct{})
f := func(job worker.Job, done <-chan struct{}) (interface{}, error) { f := func(job worker.Job, done <-chan struct{}) (interface{}, error) {
packID := job.Data.(backend.ID) packID := job.Data.(backend.ID)
entries, err := repo.ListPack(packID) entries, err := repo.ListPack(packID)
return LoadBlobsResult{ return ListAllPacksResult{
PackID: packID, PackID: packID,
Entries: entries, Entries: entries,
}, err }, err
@ -66,7 +66,7 @@ func RebuildIndex(repo *Repository) error {
continue continue
} }
res := job.Result.(LoadBlobsResult) res := job.Result.(ListAllPacksResult)
for _, entry := range res.Entries { for _, entry := range res.Entries {
pb := PackedBlob{ pb := PackedBlob{