From c0b5f5a8af1a53da8d082462a743821b4cc45c9c Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 6 Mar 2016 12:34:23 +0100 Subject: [PATCH] Fix all code which uses repository.New() --- src/cmds/restic/cmd_init.go | 6 +++++- src/cmds/restic/global.go | 5 ++++- src/restic/archiver_duplication_test.go | 6 +++++- src/restic/checker/checker_test.go | 6 ++++-- src/restic/pack/pack.go | 3 +++ src/restic/pack/pack_test.go | 5 +++-- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/cmds/restic/cmd_init.go b/src/cmds/restic/cmd_init.go index ec790fe90..069977cb6 100644 --- a/src/cmds/restic/cmd_init.go +++ b/src/cmds/restic/cmd_init.go @@ -26,7 +26,11 @@ func (cmd CmdInit) Execute(args []string) error { "enter password again: ") } - s := repository.New(be) + s, err := repository.New(be) + if err != nil { + return err + } + err = s.Init(cmd.global.password) if err != nil { cmd.global.Exitf(1, "creating key in backend at %s failed: %v\n", cmd.global.Repo, err) diff --git a/src/cmds/restic/global.go b/src/cmds/restic/global.go index 49a2ace30..1de0bfe76 100644 --- a/src/cmds/restic/global.go +++ b/src/cmds/restic/global.go @@ -208,7 +208,10 @@ func (o GlobalOptions) OpenRepository() (*repository.Repository, error) { return nil, err } - s := repository.New(be) + s, err := repository.New(be) + if err != nil { + return nil, err + } if o.password == "" { o.password = o.ReadPassword("enter password for repository: ") diff --git a/src/restic/archiver_duplication_test.go b/src/restic/archiver_duplication_test.go index 3edc70cb3..564cdca00 100644 --- a/src/restic/archiver_duplication_test.go +++ b/src/restic/archiver_duplication_test.go @@ -78,7 +78,11 @@ func testArchiverDuplication(t *testing.T) { t.Fatal(err) } - repo := repository.New(forgetfulBackend()) + repo, err := repository.New(forgetfulBackend()) + if err != nil { + t.Fatal(err) + } + err = repo.Init("foo") if err != nil { t.Fatal(err) diff --git a/src/restic/checker/checker_test.go b/src/restic/checker/checker_test.go index 85135a98c..5db7d945e 100644 --- a/src/restic/checker/checker_test.go +++ b/src/restic/checker/checker_test.go @@ -239,7 +239,8 @@ func induceError(data []byte) { func TestCheckerModifiedData(t *testing.T) { be := mem.New() - repo := repository.New(be) + repo, err := repository.New(be) + OK(t, err) OK(t, repo.Init(TestPassword)) arch := restic.NewArchiver(repo) @@ -248,7 +249,8 @@ func TestCheckerModifiedData(t *testing.T) { t.Logf("archived as %v", id.Str()) beError := &errorBackend{Backend: be} - checkRepo := repository.New(beError) + checkRepo, err := repository.New(beError) + OK(t, err) OK(t, checkRepo.SearchKey(TestPassword)) chkr := checker.New(checkRepo) diff --git a/src/restic/pack/pack.go b/src/restic/pack/pack.go index e983eae3f..931bda869 100644 --- a/src/restic/pack/pack.go +++ b/src/restic/pack/pack.go @@ -91,6 +91,9 @@ type Packer struct { // NewPacker returns a new Packer that can be used to pack blobs // together. If wr is nil, a bytes.Buffer is used. func NewPacker(k *crypto.Key, wr io.Writer) *Packer { + if wr == nil { + wr = bytes.NewBuffer(nil) + } return &Packer{k: k, wr: wr} } diff --git a/src/restic/pack/pack_test.go b/src/restic/pack/pack_test.go index 18a7a86f4..e987ced7c 100644 --- a/src/restic/pack/pack_test.go +++ b/src/restic/pack/pack_test.go @@ -38,12 +38,13 @@ func newPack(t testing.TB, k *crypto.Key) ([]Buf, []byte, uint) { // pack blobs p := pack.NewPacker(k, nil) for _, b := range bufs { - p.Add(pack.Tree, b.id, bytes.NewReader(b.data)) + p.Add(pack.Tree, b.id, b.data) } - packData, err := p.Finalize() + _, err := p.Finalize() OK(t, err) + packData := p.Writer().(*bytes.Buffer).Bytes() return bufs, packData, p.Size() }