forked from TrueCloudLab/restic
Make BlobHandle substruct of Blob
This commit is contained in:
parent
c844580e0f
commit
92bd448691
8 changed files with 67 additions and 43 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue