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

repository: Rename LoadAndDecrypt to LoadUnpacked

The method is the complement for SaveUnpacked and not for
SaveAndEncrypt. The latter assembles blobs into pack files.
This commit is contained in:
Michael Eischer 2022-02-13 00:01:27 +01:00
parent 2e1613d4c6
commit 6877e7edbb
5 changed files with 10 additions and 10 deletions

View File

@ -79,7 +79,7 @@ func runCat(gopts GlobalOptions, args []string) error {
Println(string(buf)) Println(string(buf))
return nil return nil
case "index": case "index":
buf, err := repo.LoadAndDecrypt(gopts.ctx, nil, restic.IndexFile, id) buf, err := repo.LoadUnpacked(gopts.ctx, nil, restic.IndexFile, id)
if err != nil { if err != nil {
return err return err
} }

View File

@ -53,7 +53,7 @@ func ForAllIndexes(ctx context.Context, repo restic.Repository,
var idx *Index var idx *Index
oldFormat := false oldFormat := false
buf, err = repo.LoadAndDecrypt(ctx, buf[:0], restic.IndexFile, fi.ID) buf, err = repo.LoadUnpacked(ctx, buf[:0], restic.IndexFile, fi.ID)
if err == nil { if err == nil {
idx, oldFormat, err = DecodeIndex(buf, fi.ID) idx, oldFormat, err = DecodeIndex(buf, fi.ID)
} }

View File

@ -86,10 +86,10 @@ func (r *Repository) PrefixLength(ctx context.Context, t restic.FileType) (int,
return restic.PrefixLength(ctx, r.be, t) return restic.PrefixLength(ctx, r.be, t)
} }
// LoadAndDecrypt loads and decrypts the file with the given type and ID, using // LoadUnpacked loads and decrypts the file with the given type and ID, using
// the supplied buffer (which must be empty). If the buffer is nil, a new // the supplied buffer (which must be empty). If the buffer is nil, a new
// buffer will be allocated and returned. // buffer will be allocated and returned.
func (r *Repository) LoadAndDecrypt(ctx context.Context, buf []byte, t restic.FileType, id restic.ID) ([]byte, error) { func (r *Repository) LoadUnpacked(ctx context.Context, buf []byte, t restic.FileType, id restic.ID) ([]byte, error) {
if len(buf) != 0 { if len(buf) != 0 {
panic("buf is not empty") panic("buf is not empty")
} }
@ -239,7 +239,7 @@ func (r *Repository) LoadBlob(ctx context.Context, t restic.BlobType, id restic.
// LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on // LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on
// the item. // the item.
func (r *Repository) LoadJSONUnpacked(ctx context.Context, t restic.FileType, id restic.ID, item interface{}) (err error) { func (r *Repository) LoadJSONUnpacked(ctx context.Context, t restic.FileType, id restic.ID, item interface{}) (err error) {
buf, err := r.LoadAndDecrypt(ctx, nil, t, id) buf, err := r.LoadUnpacked(ctx, nil, t, id)
if err != nil { if err != nil {
return err return err
} }

View File

@ -218,7 +218,7 @@ func BenchmarkLoadBlob(b *testing.B) {
} }
} }
func BenchmarkLoadAndDecrypt(b *testing.B) { func BenchmarkLoadUnpacked(b *testing.B) {
repo, cleanup := repository.TestRepository(b) repo, cleanup := repository.TestRepository(b)
defer cleanup() defer cleanup()
@ -237,7 +237,7 @@ func BenchmarkLoadAndDecrypt(b *testing.B) {
b.SetBytes(int64(length)) b.SetBytes(int64(length))
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
data, err := repo.LoadAndDecrypt(context.TODO(), nil, restic.PackFile, storageID) data, err := repo.LoadUnpacked(context.TODO(), nil, restic.PackFile, storageID)
rtest.OK(b, err) rtest.OK(b, err)
// See comment in BenchmarkLoadBlob. // See comment in BenchmarkLoadBlob.
@ -300,7 +300,7 @@ func TestRepositoryLoadIndex(t *testing.T) {
// loadIndex loads the index id from backend and returns it. // loadIndex loads the index id from backend and returns it.
func loadIndex(ctx context.Context, repo restic.Repository, id restic.ID) (*repository.Index, error) { func loadIndex(ctx context.Context, repo restic.Repository, id restic.ID) (*repository.Index, error) {
buf, err := repo.LoadAndDecrypt(ctx, nil, restic.IndexFile, id) buf, err := repo.LoadUnpacked(ctx, nil, restic.IndexFile, id)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -43,10 +43,10 @@ type Repository interface {
SaveJSONUnpacked(context.Context, FileType, interface{}) (ID, error) SaveJSONUnpacked(context.Context, FileType, interface{}) (ID, error)
LoadJSONUnpacked(ctx context.Context, t FileType, id ID, dest interface{}) error LoadJSONUnpacked(ctx context.Context, t FileType, id ID, dest interface{}) error
// LoadAndDecrypt loads and decrypts the file with the given type and ID, // LoadUnpacked loads and decrypts the file with the given type and ID,
// using the supplied buffer (which must be empty). If the buffer is nil, a // using the supplied buffer (which must be empty). If the buffer is nil, a
// new buffer will be allocated and returned. // new buffer will be allocated and returned.
LoadAndDecrypt(ctx context.Context, buf []byte, t FileType, id ID) (data []byte, err error) LoadUnpacked(ctx context.Context, buf []byte, t FileType, id ID) (data []byte, err error)
LoadBlob(context.Context, BlobType, ID, []byte) ([]byte, error) LoadBlob(context.Context, BlobType, ID, []byte) ([]byte, error)
SaveBlob(context.Context, BlobType, []byte, ID, bool) (ID, bool, error) SaveBlob(context.Context, BlobType, []byte, ID, bool) (ID, bool, error)