From 6877e7edbb4783a3915884440b05c1adfdeb2730 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 13 Feb 2022 00:01:27 +0100 Subject: [PATCH] repository: Rename LoadAndDecrypt to LoadUnpacked The method is the complement for SaveUnpacked and not for SaveAndEncrypt. The latter assembles blobs into pack files. --- cmd/restic/cmd_cat.go | 2 +- internal/repository/index_parallel.go | 2 +- internal/repository/repository.go | 6 +++--- internal/repository/repository_test.go | 6 +++--- internal/restic/repository.go | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index 8d31fa257..ec0535db0 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -79,7 +79,7 @@ func runCat(gopts GlobalOptions, args []string) error { Println(string(buf)) return nil 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 { return err } diff --git a/internal/repository/index_parallel.go b/internal/repository/index_parallel.go index ffe03d427..545a05921 100644 --- a/internal/repository/index_parallel.go +++ b/internal/repository/index_parallel.go @@ -53,7 +53,7 @@ func ForAllIndexes(ctx context.Context, repo restic.Repository, var idx *Index 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 { idx, oldFormat, err = DecodeIndex(buf, fi.ID) } diff --git a/internal/repository/repository.go b/internal/repository/repository.go index 39953cd88..2bd03937e 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -86,10 +86,10 @@ func (r *Repository) PrefixLength(ctx context.Context, t restic.FileType) (int, 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 // 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 { 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 // the item. 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 { return err } diff --git a/internal/repository/repository_test.go b/internal/repository/repository_test.go index 167ffa535..7cc593e04 100644 --- a/internal/repository/repository_test.go +++ b/internal/repository/repository_test.go @@ -218,7 +218,7 @@ func BenchmarkLoadBlob(b *testing.B) { } } -func BenchmarkLoadAndDecrypt(b *testing.B) { +func BenchmarkLoadUnpacked(b *testing.B) { repo, cleanup := repository.TestRepository(b) defer cleanup() @@ -237,7 +237,7 @@ func BenchmarkLoadAndDecrypt(b *testing.B) { b.SetBytes(int64(length)) 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) // See comment in BenchmarkLoadBlob. @@ -300,7 +300,7 @@ func TestRepositoryLoadIndex(t *testing.T) { // loadIndex loads the index id from backend and returns it. 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 { return nil, err } diff --git a/internal/restic/repository.go b/internal/restic/repository.go index c2a6e9f74..5e132157c 100644 --- a/internal/restic/repository.go +++ b/internal/restic/repository.go @@ -43,10 +43,10 @@ type Repository interface { SaveJSONUnpacked(context.Context, FileType, interface{}) (ID, 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 // 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) SaveBlob(context.Context, BlobType, []byte, ID, bool) (ID, bool, error)