Skip to content

Commit

Permalink
remove ConvertIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
fd0 committed Nov 8, 2015
1 parent 6c54d3f commit 5776b8f
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 78 deletions.
2 changes: 1 addition & 1 deletion cmd/restic/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ var optimizeTests = []struct {
"a13c11e582b77a693dd75ab4e3a3ba96538a056594a4b9076e4cacebe6e06d43",
},
{
filepath.Join("..", "..", "repository", "testdata", "old-index-repo.tar.gz"),
filepath.Join("testdata", "old-index-repo.tar.gz"),
"",
},
}
Expand Down
File renamed without changes.
26 changes: 0 additions & 26 deletions repository/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,32 +539,6 @@ func DecodeOldIndex(rd io.Reader) (idx *Index, err error) {
return idx, err
}

// ConvertIndexes loads all indexes from the repo and converts them to the new
// format (if necessary). When the conversion is succcessful, the old indexes
// are removed.
func ConvertIndexes(repo *Repository) error {
debug.Log("ConvertIndexes", "start")
done := make(chan struct{})
defer close(done)

for id := range repo.List(backend.Index, done) {
debug.Log("ConvertIndexes", "checking index %v", id.Str())

newID, err := ConvertIndex(repo, id)
if err != nil {
debug.Log("ConvertIndexes", "Converting index %v returns error: %v", id.Str(), err)
return err
}

if id != newID {
debug.Log("ConvertIndexes", "index %v converted to new format as %v", id.Str(), newID.Str())
}
}

debug.Log("ConvertIndexes", "done")
return nil
}

// LoadIndexWithDecoder loads the index and decodes it with fn.
func LoadIndexWithDecoder(repo *Repository, id string, fn func(io.Reader) (*Index, error)) (*Index, error) {
debug.Log("LoadIndexWithDecoder", "Loading index %v", id[:8])
Expand Down
51 changes: 0 additions & 51 deletions repository/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"crypto/rand"
"io"
"path/filepath"
"testing"

"github.com/restic/restic/backend"
Expand Down Expand Up @@ -323,56 +322,6 @@ func TestIndexUnserializeOld(t *testing.T) {
Equals(t, 0, len(idx.Supersedes()))
}

var oldIndexTestRepo = filepath.Join("testdata", "old-index-repo.tar.gz")

func TestConvertIndex(t *testing.T) {
WithTestEnvironment(t, oldIndexTestRepo, func(repodir string) {
repo := OpenLocalRepo(t, repodir)

old := make(map[backend.ID]*repository.Index)
for id := range repo.List(backend.Index, nil) {
idx, err := repository.LoadIndex(repo, id.String())
OK(t, err)
old[id] = idx
}

OK(t, repository.ConvertIndexes(repo))

for id := range repo.List(backend.Index, nil) {
idx, err := repository.LoadIndexWithDecoder(repo, id.String(), repository.DecodeIndex)
OK(t, err)

Assert(t, len(idx.Supersedes()) == 1,
"Expected index %v to supersed exactly one index, got %v", id, idx.Supersedes())

oldIndexID := idx.Supersedes()[0]

oldIndex, ok := old[oldIndexID]
Assert(t, ok,
"Index %v superseds %v, but that wasn't found in the old index map", id.Str(), oldIndexID.Str())

Assert(t, idx.Count(pack.Data) == oldIndex.Count(pack.Data),
"Index %v count blobs %v: %v != %v", id.Str(), pack.Data, idx.Count(pack.Data), oldIndex.Count(pack.Data))
Assert(t, idx.Count(pack.Tree) == oldIndex.Count(pack.Tree),
"Index %v count blobs %v: %v != %v", id.Str(), pack.Tree, idx.Count(pack.Tree), oldIndex.Count(pack.Tree))

for packedBlob := range idx.Each(nil) {
blob, err := oldIndex.Lookup(packedBlob.ID)
OK(t, err)

Assert(t, blob.PackID == packedBlob.PackID,
"Check blob %v: pack ID %v != %v", packedBlob.ID, blob.PackID, packedBlob.PackID)
Assert(t, blob.Type == packedBlob.Type,
"Check blob %v: Type %v != %v", packedBlob.ID, blob.Type, packedBlob.Type)
Assert(t, blob.Offset == packedBlob.Offset,
"Check blob %v: Type %v != %v", packedBlob.ID, blob.Offset, packedBlob.Offset)
Assert(t, blob.Length == packedBlob.Length,
"Check blob %v: Type %v != %v", packedBlob.ID, blob.Length, packedBlob.Length)
}
}
})
}

func TestIndexPacks(t *testing.T) {
idx := repository.NewIndex()
packs := backend.NewIDSet()
Expand Down

0 comments on commit 5776b8f

Please sign in to comment.