2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 02:48:55 +00:00

restic: decouple restic.Handle

This commit is contained in:
Michael Eischer 2023-10-01 10:52:57 +02:00
parent 7881309d63
commit b6d79bdf6f
6 changed files with 20 additions and 11 deletions

View File

@ -73,7 +73,7 @@ func (be *MemoryBackend) Save(ctx context.Context, h restic.Handle, rd restic.Re
be.m.Lock()
defer be.m.Unlock()
h.ContainedBlobType = restic.InvalidBlob
h.IsMetadata = false
if h.Type == restic.ConfigFile {
h.Name = ""
}
@ -120,7 +120,7 @@ func (be *MemoryBackend) openReader(ctx context.Context, h restic.Handle, length
be.m.Lock()
defer be.m.Unlock()
h.ContainedBlobType = restic.InvalidBlob
h.IsMetadata = false
if h.Type == restic.ConfigFile {
h.Name = ""
}
@ -147,7 +147,7 @@ func (be *MemoryBackend) Stat(ctx context.Context, h restic.Handle) (restic.File
be.m.Lock()
defer be.m.Unlock()
h.ContainedBlobType = restic.InvalidBlob
h.IsMetadata = false
if h.Type == restic.ConfigFile {
h.Name = ""
}
@ -165,7 +165,7 @@ func (be *MemoryBackend) Remove(ctx context.Context, h restic.Handle) error {
be.m.Lock()
defer be.m.Unlock()
h.ContainedBlobType = restic.InvalidBlob
h.IsMetadata = false
if _, ok := be.data[h]; !ok {
return errNotFound
}

View File

@ -48,7 +48,7 @@ func autoCacheTypes(h restic.Handle) bool {
case restic.IndexFile, restic.SnapshotFile:
return true
case restic.PackFile:
return h.ContainedBlobType == restic.TreeBlob
return h.IsMetadata
}
return false
}

View File

@ -163,7 +163,7 @@ func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *Packe
}
id := restic.IDFromHash(hr.Sum(nil))
h := restic.Handle{Type: restic.PackFile, Name: id.String(), ContainedBlobType: t}
h := restic.Handle{Type: restic.PackFile, Name: id.String(), IsMetadata: t.IsMetadata()}
var beHash []byte
if beHr != nil {
beHash = beHr.Sum(nil)

View File

@ -284,7 +284,7 @@ func (r *Repository) LoadBlob(ctx context.Context, t restic.BlobType, id restic.
}
// load blob from pack
h := restic.Handle{Type: restic.PackFile, Name: blob.PackID.String(), ContainedBlobType: t}
h := restic.Handle{Type: restic.PackFile, Name: blob.PackID.String(), IsMetadata: t.IsMetadata()}
switch {
case cap(buf) < int(blob.Length):
@ -922,7 +922,7 @@ func StreamPack(ctx context.Context, beLoad BackendLoadFn, key *crypto.Key, pack
}
func streamPackPart(ctx context.Context, beLoad BackendLoadFn, key *crypto.Key, packID restic.ID, blobs []restic.Blob, handleBlobFn func(blob restic.BlobHandle, buf []byte, err error) error) error {
h := restic.Handle{Type: restic.PackFile, Name: packID.String(), ContainedBlobType: restic.DataBlob}
h := restic.Handle{Type: restic.PackFile, Name: packID.String(), IsMetadata: false}
dataStart := blobs[0].Offset
dataEnd := blobs[len(blobs)-1].Offset + blobs[len(blobs)-1].Length

View File

@ -75,6 +75,15 @@ func (t BlobType) String() string {
return fmt.Sprintf("<BlobType %d>", t)
}
func (t BlobType) IsMetadata() bool {
switch t {
case TreeBlob:
return true
default:
return false
}
}
// MarshalJSON encodes the BlobType into JSON.
func (t BlobType) MarshalJSON() ([]byte, error) {
switch t {

View File

@ -41,9 +41,9 @@ func (t FileType) String() string {
// Handle is used to store and access data in a backend.
type Handle struct {
Type FileType
ContainedBlobType BlobType
Name string
Type FileType
IsMetadata bool
Name string
}
func (h Handle) String() string {