From 723592d9238d0ade0ea2eef5c553489d47291b82 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 1 Aug 2016 18:31:44 +0200 Subject: [PATCH] Move FindUsedBlobs to package restic --- src/restic/find.go | 12 +++++++++ src/restic/find_test.go | 42 +++++++++++++++++++++++++++++ src/restic/repository/prune.go | 6 ----- src/restic/repository/prune_test.go | 36 ------------------------- 4 files changed, 54 insertions(+), 42 deletions(-) create mode 100644 src/restic/find.go create mode 100644 src/restic/find_test.go diff --git a/src/restic/find.go b/src/restic/find.go new file mode 100644 index 000000000..baeb47ca9 --- /dev/null +++ b/src/restic/find.go @@ -0,0 +1,12 @@ +package restic + +import ( + "restic/backend" + "restic/repository" +) + +// FindUsedBlobs traverses the tree ID and returns a set of all blobs +// encountered. +func FindUsedBlobs(repo *repository.Repository, treeID backend.ID) (backend.IDSet, error) { + return nil, nil +} diff --git a/src/restic/find_test.go b/src/restic/find_test.go new file mode 100644 index 000000000..f5973b9ae --- /dev/null +++ b/src/restic/find_test.go @@ -0,0 +1,42 @@ +package restic + +import ( + "testing" + "time" + + "restic/repository" +) + +const ( + testSnapshots = 3 + testDepth = 2 +) + +var testTime = 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) + t.Logf("snapshot %v saved, tree %v", sn.ID().Str(), sn.Tree.Str()) + snapshots = append(snapshots, sn) + } + + for _, sn := range snapshots { + usedBlobs, err := FindUsedBlobs(repo, *sn.Tree) + if err != nil { + t.Errorf("FindUsedBlobs returned error: %v", err) + continue + } + + if len(usedBlobs) == 0 { + t.Errorf("FindUsedBlobs returned an empty set") + continue + } + + t.Logf("used blobs from snapshot %v (tree %v): %v", sn.ID().Str(), sn.Tree.Str(), usedBlobs) + } +} diff --git a/src/restic/repository/prune.go b/src/restic/repository/prune.go index f0b901948..75f9f9ac7 100644 --- a/src/restic/repository/prune.go +++ b/src/restic/repository/prune.go @@ -174,9 +174,3 @@ func RebuildIndex(repo *Repository) error { return nil } - -// FindUsedBlobs traverses the tree ID and returns a set of all blobs -// encountered. -func FindUsedBlobs(repo *Repository, treeID backend.ID) (backend.IDSet, error) { - return nil, nil -} diff --git a/src/restic/repository/prune_test.go b/src/restic/repository/prune_test.go index ce6c3748b..9b40e92bd 100644 --- a/src/restic/repository/prune_test.go +++ b/src/restic/repository/prune_test.go @@ -3,12 +3,10 @@ package repository_test import ( "io" "math/rand" - "restic" "restic/backend" "restic/pack" "restic/repository" "testing" - "time" ) func randomSize(min, max int) int { @@ -192,37 +190,3 @@ func TestRepack(t *testing.T) { } } } - -const ( - testSnapshots = 3 - testDepth = 2 -) - -var testTime = time.Unix(1469960361, 23) - -func TestFindUsedBlobs(t *testing.T) { - repo, cleanup := repository.TestRepository(t) - defer cleanup() - - var snapshots []*restic.Snapshot - for i := 0; i < testSnapshots; i++ { - sn := restic.TestCreateSnapshot(t, repo, testTime.Add(time.Duration(i)*time.Second), testDepth) - t.Logf("snapshot %v saved, tree %v", sn.ID().Str(), sn.Tree.Str()) - snapshots = append(snapshots, sn) - } - - for _, sn := range snapshots { - usedBlobs, err := repository.FindUsedBlobs(repo, *sn.Tree) - if err != nil { - t.Errorf("FindUsedBlobs returned error: %v", err) - continue - } - - if len(usedBlobs) == 0 { - t.Errorf("FindUsedBlobs returned an empty set") - continue - } - - t.Logf("used blobs from snapshot %v (tree %v): %v", sn.ID().Str(), sn.Tree.Str(), usedBlobs) - } -}