restic: decouple restic.Handle
This commit is contained in:
parent
7881309d63
commit
b6d79bdf6f
6 changed files with 20 additions and 11 deletions
|
@ -73,7 +73,7 @@ func (be *MemoryBackend) Save(ctx context.Context, h restic.Handle, rd restic.Re
|
||||||
be.m.Lock()
|
be.m.Lock()
|
||||||
defer be.m.Unlock()
|
defer be.m.Unlock()
|
||||||
|
|
||||||
h.ContainedBlobType = restic.InvalidBlob
|
h.IsMetadata = false
|
||||||
if h.Type == restic.ConfigFile {
|
if h.Type == restic.ConfigFile {
|
||||||
h.Name = ""
|
h.Name = ""
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ func (be *MemoryBackend) openReader(ctx context.Context, h restic.Handle, length
|
||||||
be.m.Lock()
|
be.m.Lock()
|
||||||
defer be.m.Unlock()
|
defer be.m.Unlock()
|
||||||
|
|
||||||
h.ContainedBlobType = restic.InvalidBlob
|
h.IsMetadata = false
|
||||||
if h.Type == restic.ConfigFile {
|
if h.Type == restic.ConfigFile {
|
||||||
h.Name = ""
|
h.Name = ""
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ func (be *MemoryBackend) Stat(ctx context.Context, h restic.Handle) (restic.File
|
||||||
be.m.Lock()
|
be.m.Lock()
|
||||||
defer be.m.Unlock()
|
defer be.m.Unlock()
|
||||||
|
|
||||||
h.ContainedBlobType = restic.InvalidBlob
|
h.IsMetadata = false
|
||||||
if h.Type == restic.ConfigFile {
|
if h.Type == restic.ConfigFile {
|
||||||
h.Name = ""
|
h.Name = ""
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ func (be *MemoryBackend) Remove(ctx context.Context, h restic.Handle) error {
|
||||||
be.m.Lock()
|
be.m.Lock()
|
||||||
defer be.m.Unlock()
|
defer be.m.Unlock()
|
||||||
|
|
||||||
h.ContainedBlobType = restic.InvalidBlob
|
h.IsMetadata = false
|
||||||
if _, ok := be.data[h]; !ok {
|
if _, ok := be.data[h]; !ok {
|
||||||
return errNotFound
|
return errNotFound
|
||||||
}
|
}
|
||||||
|
|
2
internal/cache/backend.go
vendored
2
internal/cache/backend.go
vendored
|
@ -48,7 +48,7 @@ func autoCacheTypes(h restic.Handle) bool {
|
||||||
case restic.IndexFile, restic.SnapshotFile:
|
case restic.IndexFile, restic.SnapshotFile:
|
||||||
return true
|
return true
|
||||||
case restic.PackFile:
|
case restic.PackFile:
|
||||||
return h.ContainedBlobType == restic.TreeBlob
|
return h.IsMetadata
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *Packe
|
||||||
}
|
}
|
||||||
|
|
||||||
id := restic.IDFromHash(hr.Sum(nil))
|
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
|
var beHash []byte
|
||||||
if beHr != nil {
|
if beHr != nil {
|
||||||
beHash = beHr.Sum(nil)
|
beHash = beHr.Sum(nil)
|
||||||
|
|
|
@ -284,7 +284,7 @@ func (r *Repository) LoadBlob(ctx context.Context, t restic.BlobType, id restic.
|
||||||
}
|
}
|
||||||
|
|
||||||
// load blob from pack
|
// 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 {
|
switch {
|
||||||
case cap(buf) < int(blob.Length):
|
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 {
|
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
|
dataStart := blobs[0].Offset
|
||||||
dataEnd := blobs[len(blobs)-1].Offset + blobs[len(blobs)-1].Length
|
dataEnd := blobs[len(blobs)-1].Offset + blobs[len(blobs)-1].Length
|
||||||
|
|
|
@ -75,6 +75,15 @@ func (t BlobType) String() string {
|
||||||
return fmt.Sprintf("<BlobType %d>", t)
|
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.
|
// MarshalJSON encodes the BlobType into JSON.
|
||||||
func (t BlobType) MarshalJSON() ([]byte, error) {
|
func (t BlobType) MarshalJSON() ([]byte, error) {
|
||||||
switch t {
|
switch t {
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (t FileType) String() string {
|
||||||
// Handle is used to store and access data in a backend.
|
// Handle is used to store and access data in a backend.
|
||||||
type Handle struct {
|
type Handle struct {
|
||||||
Type FileType
|
Type FileType
|
||||||
ContainedBlobType BlobType
|
IsMetadata bool
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue