Fix stylistic issues with FindUsedBlobs

This commit is contained in:
Alexander Neumann 2016-08-01 20:44:02 +02:00
parent 6227821b4e
commit 50b724ca23
2 changed files with 11 additions and 12 deletions

View File

@ -5,7 +5,7 @@ import (
"restic/repository"
)
// FindUsedBlobs traverse the tree ID and adds all seen blobs to blobs.
// findUsedBlobs traverse the tree ID and adds all seen blobs to blobs.
func findUsedBlobs(repo *repository.Repository, treeID backend.ID, blobs backend.IDSet, seen backend.IDSet) error {
blobs.Insert(treeID)
@ -38,9 +38,7 @@ func findUsedBlobs(repo *repository.Repository, treeID backend.ID, blobs backend
return nil
}
// FindUsedBlobs traverses the tree ID and returns a set of all blobs
// encountered.
func FindUsedBlobs(repo *repository.Repository, treeID backend.ID) (blobs backend.IDSet, err error) {
blobs = backend.NewIDSet()
return blobs, findUsedBlobs(repo, treeID, blobs, backend.NewIDSet())
// 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 backend.IDSet) error {
return findUsedBlobs(repo, treeID, blobs, backend.NewIDSet())
}

View File

@ -65,25 +65,26 @@ func saveIDSet(t testing.TB, filename string, s backend.IDSet) {
var updateGoldenFiles = flag.Bool("update", false, "update golden files in testdata/")
const (
testSnapshots = 3
testDepth = 2
findTestSnapshots = 3
findTestDepth = 2
)
var testTime = time.Unix(1469960361, 23)
var findTestTime = time.Unix(1469960361, 23)
func TestFindUsedBlobs(t *testing.T) {
repo, cleanup := repository.TestRepository(t)
defer cleanup()
var snapshots []*Snapshot
for i := 0; i < testSnapshots; i++ {
sn := TestCreateSnapshot(t, repo, testTime.Add(time.Duration(i)*time.Second), testDepth)
for i := 0; i < findTestSnapshots; i++ {
sn := TestCreateSnapshot(t, repo, findTestTime.Add(time.Duration(i)*time.Second), findTestDepth)
t.Logf("snapshot %v saved, tree %v", sn.ID().Str(), sn.Tree.Str())
snapshots = append(snapshots, sn)
}
for i, sn := range snapshots {
usedBlobs, err := FindUsedBlobs(repo, *sn.Tree)
usedBlobs := backend.NewIDSet()
err := FindUsedBlobs(repo, *sn.Tree, usedBlobs)
if err != nil {
t.Errorf("FindUsedBlobs returned error: %v", err)
continue