diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index 6f3b7db12..ea33cceb6 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -231,7 +231,7 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB // iterate over all blobs in index to find out which blobs are duplicates for blob := range repo.Index().Each(ctx) { - bh := blob.Handle() + bh := blob.BlobHandle size := uint64(blob.Length) switch { case usedBlobs.Has(bh): // used blob, move to keepBlobs @@ -280,7 +280,7 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB ip.tpe = restic.InvalidBlob } - bh := blob.Handle() + bh := blob.BlobHandle size := uint64(blob.Length) switch { case duplicateBlobs.Has(bh): // duplicate blob diff --git a/internal/pack/pack.go b/internal/pack/pack.go index 0c26e6a75..c22f434d1 100644 --- a/internal/pack/pack.go +++ b/internal/pack/pack.go @@ -35,7 +35,7 @@ func (p *Packer) Add(t restic.BlobType, id restic.ID, data []byte) (int, error) p.m.Lock() defer p.m.Unlock() - c := restic.Blob{Type: t, ID: id} + c := restic.Blob{BlobHandle: restic.BlobHandle{Type: t, ID: id}} n, err := p.wr.Write(data) c.Length = uint(n) diff --git a/internal/repository/index.go b/internal/repository/index.go index 997e9b708..ce51db46f 100644 --- a/internal/repository/index.go +++ b/internal/repository/index.go @@ -165,8 +165,8 @@ func (idx *Index) StorePack(id restic.ID, blobs []restic.Blob) { func (idx *Index) toPackedBlob(e *indexEntry, typ restic.BlobType) restic.PackedBlob { return restic.PackedBlob{ Blob: restic.Blob{ - ID: e.id, - Type: typ, + BlobHandle: restic.BlobHandle{ID: e.id, + Type: typ}, Length: uint(e.length), Offset: uint(e.offset), }, @@ -596,8 +596,8 @@ func DecodeIndex(buf []byte, id restic.ID) (idx *Index, oldFormat bool, err erro for _, blob := range pack.Blobs { idx.store(packID, restic.Blob{ - Type: blob.Type, - ID: blob.ID, + BlobHandle: restic.BlobHandle{Type: blob.Type, + ID: blob.ID}, Offset: blob.Offset, Length: blob.Length, }) @@ -640,8 +640,9 @@ func decodeOldIndex(buf []byte) (idx *Index, err error) { for _, blob := range pack.Blobs { idx.store(packID, restic.Blob{ - Type: blob.Type, - ID: blob.ID, + BlobHandle: restic.BlobHandle{ + Type: blob.Type, + ID: blob.ID}, Offset: blob.Offset, Length: blob.Length, }) diff --git a/internal/repository/index_test.go b/internal/repository/index_test.go index 9ac208229..ef2cfb19d 100644 --- a/internal/repository/index_test.go +++ b/internal/repository/index_test.go @@ -32,8 +32,10 @@ func TestIndexSerialize(t *testing.T) { length := uint(i*100 + j) idx.Store(restic.PackedBlob{ Blob: restic.Blob{ - Type: restic.DataBlob, - ID: id, + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: id, + }, Offset: pos, Length: length, }, @@ -105,8 +107,10 @@ func TestIndexSerialize(t *testing.T) { length := uint(i*100 + j) idx.Store(restic.PackedBlob{ Blob: restic.Blob{ - Type: restic.DataBlob, - ID: id, + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: id, + }, Offset: pos, Length: length, }, @@ -178,8 +182,10 @@ func TestIndexSize(t *testing.T) { length := uint(i*100 + j) idx.Store(restic.PackedBlob{ Blob: restic.Blob{ - Type: restic.DataBlob, - ID: id, + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: id, + }, Offset: pos, Length: length, }, @@ -395,8 +401,10 @@ func TestIndexPacks(t *testing.T) { packID := restic.NewRandomID() idx.Store(restic.PackedBlob{ Blob: restic.Blob{ - Type: restic.DataBlob, - ID: restic.NewRandomID(), + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: restic.NewRandomID(), + }, Offset: 0, Length: 23, }, @@ -431,8 +439,10 @@ func createRandomIndex(rng *rand.Rand, packfiles int) (idx *repository.Index, lo size := 2000 + rng.Intn(4*1024*1024) id := NewRandomTestID(rng) blobs = append(blobs, restic.Blob{ - Type: restic.DataBlob, - ID: id, + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: id, + }, Length: uint(size), Offset: uint(offset), }) @@ -511,8 +521,10 @@ func TestIndexHas(t *testing.T) { length := uint(i*100 + j) idx.Store(restic.PackedBlob{ Blob: restic.Blob{ - Type: restic.DataBlob, - ID: id, + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: id, + }, Offset: pos, Length: length, }, diff --git a/internal/repository/master_index_test.go b/internal/repository/master_index_test.go index 0d56cd097..dc3a2f8b0 100644 --- a/internal/repository/master_index_test.go +++ b/internal/repository/master_index_test.go @@ -21,8 +21,10 @@ func TestMasterIndex(t *testing.T) { blob1 := restic.PackedBlob{ PackID: restic.NewRandomID(), Blob: restic.Blob{ - Type: restic.DataBlob, - ID: idInIdx1, + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: idInIdx1, + }, Length: uint(restic.CiphertextLength(10)), Offset: 0, }, @@ -31,8 +33,10 @@ func TestMasterIndex(t *testing.T) { blob2 := restic.PackedBlob{ PackID: restic.NewRandomID(), Blob: restic.Blob{ - Type: restic.DataBlob, - ID: idInIdx2, + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: idInIdx2, + }, Length: uint(restic.CiphertextLength(100)), Offset: 10, }, @@ -41,8 +45,10 @@ func TestMasterIndex(t *testing.T) { blob12a := restic.PackedBlob{ PackID: restic.NewRandomID(), Blob: restic.Blob{ - Type: restic.TreeBlob, - ID: idInIdx12, + BlobHandle: restic.BlobHandle{ + Type: restic.TreeBlob, + ID: idInIdx12, + }, Length: uint(restic.CiphertextLength(123)), Offset: 110, }, @@ -51,8 +57,10 @@ func TestMasterIndex(t *testing.T) { blob12b := restic.PackedBlob{ PackID: restic.NewRandomID(), Blob: restic.Blob{ - Type: restic.TreeBlob, - ID: idInIdx12, + BlobHandle: restic.BlobHandle{ + Type: restic.TreeBlob, + ID: idInIdx12, + }, Length: uint(restic.CiphertextLength(123)), Offset: 50, }, @@ -139,8 +147,10 @@ func TestMasterMergeFinalIndexes(t *testing.T) { blob1 := restic.PackedBlob{ PackID: restic.NewRandomID(), Blob: restic.Blob{ - Type: restic.DataBlob, - ID: idInIdx1, + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: idInIdx1, + }, Length: 10, Offset: 0, }, @@ -149,8 +159,10 @@ func TestMasterMergeFinalIndexes(t *testing.T) { blob2 := restic.PackedBlob{ PackID: restic.NewRandomID(), Blob: restic.Blob{ - Type: restic.DataBlob, - ID: idInIdx2, + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: idInIdx2, + }, Length: 100, Offset: 10, }, diff --git a/internal/repository/repository_test.go b/internal/repository/repository_test.go index 79fee8aa5..0a7e11b5f 100644 --- a/internal/repository/repository_test.go +++ b/internal/repository/repository_test.go @@ -296,9 +296,11 @@ func BenchmarkLoadIndex(b *testing.B) { for i := 0; i < 5000; i++ { idx.Store(restic.PackedBlob{ Blob: restic.Blob{ - Type: restic.DataBlob, + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: restic.NewRandomID(), + }, Length: 1234, - ID: restic.NewRandomID(), Offset: 1235, }, PackID: restic.NewRandomID(), diff --git a/internal/restic/blob.go b/internal/restic/blob.go index b6c5a47cf..44a02df0d 100644 --- a/internal/restic/blob.go +++ b/internal/restic/blob.go @@ -8,9 +8,8 @@ import ( // Blob is one part of a file or a tree. type Blob struct { - Type BlobType + BlobHandle Length uint - ID ID Offset uint } @@ -19,10 +18,6 @@ func (b Blob) String() string { b.Type, b.ID.Str(), b.Offset, b.Length) } -func (b Blob) Handle() BlobHandle { - return BlobHandle{ID: b.ID, Type: b.Type} -} - // PackedBlob is a blob stored within a file. type PackedBlob struct { Blob diff --git a/internal/restorer/filerestorer_test.go b/internal/restorer/filerestorer_test.go index 16fce6271..89669eaf9 100644 --- a/internal/restorer/filerestorer_test.go +++ b/internal/restorer/filerestorer_test.go @@ -92,8 +92,10 @@ func newTestRepo(content []TestFile) *TestRepo { if _, found := pack.blobs[blobID]; !found { blobData := seal([]byte(blob.data)) pack.blobs[blobID] = restic.Blob{ - Type: restic.DataBlob, - ID: blobID, + BlobHandle: restic.BlobHandle{ + Type: restic.DataBlob, + ID: blobID, + }, Length: uint(len(blobData)), Offset: uint(len(pack.data)), }