Replace fmt.Errorf() by errors.Errorf()

This commit is contained in:
Alexander Neumann 2016-08-21 17:48:36 +02:00
parent 444a268ce0
commit 72aa6be38d
34 changed files with 100 additions and 92 deletions

View File

@ -240,7 +240,7 @@ func filterExisting(items []string) (result []string, err error) {
func (cmd CmdBackup) readFromStdin(args []string) error {
if len(args) != 0 {
return fmt.Errorf("when reading from stdin, no additional files can be specified")
return errors.Errorf("when reading from stdin, no additional files can be specified")
}
repo, err := cmd.global.OpenRepository()
@ -274,7 +274,7 @@ func (cmd CmdBackup) Execute(args []string) error {
}
if len(args) == 0 {
return fmt.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
return errors.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
}
target := make([]string, 0, len(args))
@ -312,7 +312,7 @@ func (cmd CmdBackup) Execute(args []string) error {
if !cmd.Force && cmd.Parent != "" {
id, err := restic.FindSnapshot(repo, cmd.Parent)
if err != nil {
return fmt.Errorf("invalid id %q: %v", cmd.Parent, err)
return errors.Errorf("invalid id %q: %v", cmd.Parent, err)
}
parentSnapshotID = &id

View File

@ -26,7 +26,7 @@ func (cmd CmdCache) Usage() string {
func (cmd CmdCache) Execute(args []string) error {
// if len(args) == 0 || len(args) > 2 {
// return fmt.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
// return errors.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
// }
repo, err := cmd.global.OpenRepository()

View File

@ -34,7 +34,7 @@ func (cmd CmdCat) Usage() string {
func (cmd CmdCat) Execute(args []string) error {
if len(args) < 1 || (args[0] != "masterkey" && args[0] != "config" && len(args) != 2) {
return fmt.Errorf("type or ID not specified, Usage: %s", cmd.Usage())
return errors.Errorf("type or ID not specified, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@ -105,7 +105,7 @@ func (cmd CmdCheck) Execute(args []string) error {
for _, err := range errs {
cmd.global.Warnf("error: %v\n", err)
}
return fmt.Errorf("LoadIndex returned errors")
return errors.Errorf("LoadIndex returned errors")
}
done := make(chan struct{})

View File

@ -204,7 +204,7 @@ func (cmd CmdDump) DumpIndexes() error {
func (cmd CmdDump) Execute(args []string) error {
if len(args) != 1 {
return fmt.Errorf("type not specified, Usage: %s", cmd.Usage())
return errors.Errorf("type not specified, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@ -1,10 +1,11 @@
package main
import (
"fmt"
"path/filepath"
"time"
"github.com/pkg/errors"
"restic"
"restic/backend"
"restic/debug"
@ -57,7 +58,7 @@ func parseTime(str string) (time.Time, error) {
}
}
return time.Time{}, fmt.Errorf("unable to parse time: %q", str)
return time.Time{}, errors.Errorf("unable to parse time: %q", str)
}
func (c CmdFind) findInTree(repo *repository.Repository, id backend.ID, path string) ([]findResult, error) {
@ -137,7 +138,7 @@ func (CmdFind) Usage() string {
func (c CmdFind) Execute(args []string) error {
if len(args) != 1 {
return fmt.Errorf("wrong number of arguments, Usage: %s", c.Usage())
return errors.Errorf("wrong number of arguments, Usage: %s", c.Usage())
}
var err error
@ -177,7 +178,7 @@ func (c CmdFind) Execute(args []string) error {
if c.Snapshot != "" {
snapshotID, err := restic.FindSnapshot(repo, c.Snapshot)
if err != nil {
return fmt.Errorf("invalid id %q: %v", args[1], err)
return errors.Errorf("invalid id %q: %v", args[1], err)
}
return c.findInSnapshot(repo, snapshotID)

View File

@ -70,7 +70,7 @@ func (cmd CmdKey) getNewPassword() string {
func (cmd CmdKey) addKey(repo *repository.Repository) error {
id, err := repository.AddKey(repo, cmd.getNewPassword(), repo.Key())
if err != nil {
return fmt.Errorf("creating new key failed: %v\n", err)
return errors.Errorf("creating new key failed: %v\n", err)
}
cmd.global.Verbosef("saved new key as %s\n", id)
@ -95,7 +95,7 @@ func (cmd CmdKey) deleteKey(repo *repository.Repository, name string) error {
func (cmd CmdKey) changePassword(repo *repository.Repository) error {
id, err := repository.AddKey(repo, cmd.getNewPassword(), repo.Key())
if err != nil {
return fmt.Errorf("creating new key failed: %v\n", err)
return errors.Errorf("creating new key failed: %v\n", err)
}
err = repo.Backend().Remove(backend.Key, repo.KeyName())
@ -114,7 +114,7 @@ func (cmd CmdKey) Usage() string {
func (cmd CmdKey) Execute(args []string) error {
if len(args) < 1 || (args[0] == "rm" && len(args) != 2) {
return fmt.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
return errors.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@ -1,8 +1,6 @@
package main
import (
"fmt"
"github.com/pkg/errors"
"restic/backend"
@ -28,7 +26,7 @@ func (cmd CmdList) Usage() string {
func (cmd CmdList) Execute(args []string) error {
if len(args) != 1 {
return fmt.Errorf("type not specified, Usage: %s", cmd.Usage())
return errors.Errorf("type not specified, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"github.com/pkg/errors"
"restic"
"restic/backend"
"restic/repository"
@ -72,7 +74,7 @@ func (cmd CmdLs) Usage() string {
func (cmd CmdLs) Execute(args []string) error {
if len(args) < 1 || len(args) > 2 {
return fmt.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
return errors.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@ -4,9 +4,10 @@
package main
import (
"fmt"
"os"
"github.com/pkg/errors"
resticfs "restic/fs"
"restic/fuse"
@ -42,7 +43,7 @@ func (cmd CmdMount) Usage() string {
func (cmd CmdMount) Execute(args []string) error {
if len(args) == 0 {
return fmt.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
return errors.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@ -11,6 +11,8 @@ import (
"restic/repository"
"time"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh/terminal"
)
@ -191,7 +193,7 @@ nextPack:
removePacks.Insert(packID)
if !rewritePacks.Has(packID) {
return fmt.Errorf("pack %v is unneeded, but not contained in rewritePacks", packID.Str())
return errors.Errorf("pack %v is unneeded, but not contained in rewritePacks", packID.Str())
}
rewritePacks.Delete(packID)

View File

@ -1,8 +1,6 @@
package main
import (
"fmt"
"github.com/pkg/errors"
"restic"
@ -37,7 +35,7 @@ func (cmd CmdRestore) Usage() string {
func (cmd CmdRestore) Execute(args []string) error {
if len(args) != 1 {
return fmt.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
return errors.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
}
if cmd.Target == "" {

View File

@ -8,6 +8,8 @@ import (
"sort"
"strings"
"github.com/pkg/errors"
"restic"
"restic/backend"
)
@ -70,7 +72,7 @@ func (cmd CmdSnapshots) Usage() string {
func (cmd CmdSnapshots) Execute(args []string) error {
if len(args) != 0 {
return fmt.Errorf("wrong number of arguments, usage: %s", cmd.Usage())
return errors.Errorf("wrong number of arguments, usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@ -263,7 +263,7 @@ func (o GlobalOptions) OpenRepository() (*repository.Repository, error) {
err = s.SearchKey(o.password, maxKeys)
if err != nil {
return nil, fmt.Errorf("unable to open repo: %v", err)
return nil, errors.Errorf("unable to open repo: %v", err)
}
return s, nil
@ -301,7 +301,7 @@ func open(s string) (backend.Backend, error) {
}
debug.Log("open", "invalid repository location: %v", s)
return nil, fmt.Errorf("invalid scheme %q", loc.Scheme)
return nil, errors.Errorf("invalid scheme %q", loc.Scheme)
}
// Create the backend specified by URI.
@ -336,5 +336,5 @@ func create(s string) (backend.Backend, error) {
}
debug.Log("open", "invalid repository scheme: %v", s)
return nil, fmt.Errorf("invalid scheme %q", loc.Scheme)
return nil, errors.Errorf("invalid scheme %q", loc.Scheme)
}

View File

@ -4,13 +4,14 @@
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
"github.com/pkg/errors"
"restic"
"restic/backend"
"restic/repository"
@ -50,7 +51,7 @@ func waitForMount(dir string) error {
time.Sleep(mountSleep)
}
return fmt.Errorf("subdir %q of dir %s never appeared", mountTestSubdir, dir)
return errors.Errorf("subdir %q of dir %s never appeared", mountTestSubdir, dir)
}
func cmdMount(t testing.TB, global GlobalOptions, dir string, ready, done chan struct{}) {

View File

@ -15,6 +15,8 @@ import (
"testing"
"time"
"github.com/pkg/errors"
"restic/backend"
"restic/debug"
"restic/filter"
@ -579,7 +581,7 @@ func testFileSize(filename string, size int64) error {
}
if fi.Size() != size {
return fmt.Errorf("wrong file size for %v: expected %v, got %v", filename, size, fi.Size())
return errors.Errorf("wrong file size for %v: expected %v, got %v", filename, size, fi.Size())
}
return nil

View File

@ -178,7 +178,7 @@ func waitForResults(resultChannels [](<-chan saveResult)) ([]saveResult, error)
}
if len(results) != len(resultChannels) {
return nil, fmt.Errorf("chunker returned %v chunks, but only %v blobs saved", len(resultChannels), len(results))
return nil, errors.Errorf("chunker returned %v chunks, but only %v blobs saved", len(resultChannels), len(results))
}
return results, nil
@ -198,7 +198,7 @@ func updateNodeContent(node *Node, results []saveResult) error {
}
if bytes != node.Size {
return fmt.Errorf("errors saving node %q: saved %d bytes, wanted %d bytes", node.path, bytes, node.Size)
return errors.Errorf("errors saving node %q: saved %d bytes, wanted %d bytes", node.path, bytes, node.Size)
}
debug.Log("Archiver.SaveFile", "SaveFile(%q): %v blobs\n", node.path, len(results))

View File

@ -34,7 +34,7 @@ func (h Handle) Valid() error {
case Index:
case Config:
default:
return fmt.Errorf("invalid Type %q", h.Type)
return errors.Errorf("invalid Type %q", h.Type)
}
if h.Type == Config {

View File

@ -1,7 +1,6 @@
package local
import (
"fmt"
"io"
"io/ioutil"
"os"
@ -36,7 +35,7 @@ func Open(dir string) (*Local, error) {
// test if all necessary dirs are there
for _, d := range paths(dir) {
if _, err := fs.Stat(d); err != nil {
return nil, fmt.Errorf("%s does not exist", d)
return nil, errors.Errorf("%s does not exist", d)
}
}
@ -185,7 +184,7 @@ func (b *Local) Save(h backend.Handle, p []byte) (err error) {
// test if new path already exists
if _, err := fs.Stat(filename); err == nil {
return fmt.Errorf("Rename(): file %v already exists", filename)
return errors.Errorf("Rename(): file %v already exists", filename)
}
// create directories if necessary, ignore errors

View File

@ -113,7 +113,7 @@ func (b *restBackend) Load(h backend.Handle, p []byte, off int64) (n int, err er
return 0, err
}
if resp.StatusCode != 200 && resp.StatusCode != 206 {
return 0, fmt.Errorf("unexpected HTTP response code %v", resp.StatusCode)
return 0, errors.Errorf("unexpected HTTP response code %v", resp.StatusCode)
}
return io.ReadFull(resp.Body, p)
@ -144,7 +144,7 @@ func (b *restBackend) Save(h backend.Handle, p []byte) (err error) {
}
if resp.StatusCode != 200 {
return fmt.Errorf("unexpected HTTP response code %v", resp.StatusCode)
return errors.Errorf("unexpected HTTP response code %v", resp.StatusCode)
}
return nil
@ -168,7 +168,7 @@ func (b *restBackend) Stat(h backend.Handle) (backend.BlobInfo, error) {
}
if resp.StatusCode != 200 {
return backend.BlobInfo{}, fmt.Errorf("unexpected HTTP response code %v", resp.StatusCode)
return backend.BlobInfo{}, errors.Errorf("unexpected HTTP response code %v", resp.StatusCode)
}
if resp.ContentLength < 0 {

View File

@ -1,7 +1,6 @@
package sftp
import (
"fmt"
"net/url"
"path"
"strings"
@ -35,7 +34,7 @@ func ParseConfig(s string) (interface{}, error) {
host = url.Host
dir = url.Path
if dir == "" {
return nil, fmt.Errorf("invalid backend %q, no directory specified", s)
return nil, errors.Errorf("invalid backend %q, no directory specified", s)
}
dir = dir[1:]

View File

@ -80,7 +80,7 @@ func startClient(program string, args ...string) (*SFTP, error) {
// open the SFTP session
client, err := sftp.NewClientPipe(rd, wr)
if err != nil {
return nil, fmt.Errorf("unable to start the sftp session, error: %v", err)
return nil, errors.Errorf("unable to start the sftp session, error: %v", err)
}
return &SFTP{c: client, cmd: cmd, result: ch}, nil
@ -126,7 +126,7 @@ func Open(dir string, program string, args ...string) (*SFTP, error) {
// test if all necessary dirs and files are there
for _, d := range paths(dir) {
if _, err := sftp.c.Lstat(d); err != nil {
return nil, fmt.Errorf("%s does not exist", d)
return nil, errors.Errorf("%s does not exist", d)
}
}
@ -207,7 +207,7 @@ func (r *SFTP) tempFile() (string, *sftp.File, error) {
buf := make([]byte, tempfileRandomSuffixLength)
_, err := io.ReadFull(rand.Reader, buf)
if err != nil {
return "", nil, fmt.Errorf("unable to read %d random bytes for tempfile name: %v",
return "", nil, errors.Errorf("unable to read %d random bytes for tempfile name: %v",
tempfileRandomSuffixLength, err)
}
@ -217,7 +217,7 @@ func (r *SFTP) tempFile() (string, *sftp.File, error) {
// create file in temp dir
f, err := r.c.Create(name)
if err != nil {
return "", nil, fmt.Errorf("creating tempfile %q failed: %v", name, err)
return "", nil, errors.Errorf("creating tempfile %q failed: %v", name, err)
}
return name, f, nil
@ -231,7 +231,7 @@ func (r *SFTP) mkdirAll(dir string, mode os.FileMode) error {
return nil
}
return fmt.Errorf("mkdirAll(%s): entry exists but is not a directory", dir)
return errors.Errorf("mkdirAll(%s): entry exists but is not a directory", dir)
}
// create parent directories
@ -244,11 +244,11 @@ func (r *SFTP) mkdirAll(dir string, mode os.FileMode) error {
fi, err = r.c.Lstat(dir)
if err != nil {
// return previous errors
return fmt.Errorf("mkdirAll(%s): unable to create directories: %v, %v", dir, errMkdirAll, errMkdir)
return errors.Errorf("mkdirAll(%s): unable to create directories: %v, %v", dir, errMkdirAll, errMkdir)
}
if !fi.IsDir() {
return fmt.Errorf("mkdirAll(%s): entry exists but is not a directory", dir)
return errors.Errorf("mkdirAll(%s): entry exists but is not a directory", dir)
}
// set mode
@ -269,7 +269,7 @@ func (r *SFTP) renameFile(oldname string, t backend.Type, name string) error {
// test if new file exists
if _, err := r.c.Lstat(filename); err == nil {
return fmt.Errorf("Close(): file %v already exists", filename)
return errors.Errorf("Close(): file %v already exists", filename)
}
err := r.c.Rename(oldname, filename)
@ -396,7 +396,7 @@ func (r *SFTP) Save(h backend.Handle, p []byte) (err error) {
debug.Log("sftp.Save", "save %v: rename %v: %v",
h, path.Base(filename), err)
if err != nil {
return fmt.Errorf("sftp: renameFile: %v", err)
return errors.Errorf("sftp: renameFile: %v", err)
}
return nil

View File

@ -1,7 +1,6 @@
package restic
import (
"fmt"
"io"
"os"
"path/filepath"
@ -156,7 +155,7 @@ func (c *Cache) list(t backend.Type) ([]cacheEntry, error) {
case backend.Snapshot:
dir = filepath.Join(c.base, "snapshots")
default:
return nil, fmt.Errorf("cache not supported for type %v", t)
return nil, errors.Errorf("cache not supported for type %v", t)
}
fd, err := fs.Open(dir)
@ -208,7 +207,7 @@ func (c *Cache) filename(t backend.Type, subtype string, id backend.ID) (string,
return filepath.Join(c.base, "snapshots", filename), nil
}
return "", fmt.Errorf("cache not supported for type %v", t)
return "", errors.Errorf("cache not supported for type %v", t)
}
func getCacheDir() (string, error) {
@ -246,7 +245,7 @@ func getWindowsCacheDir() (string, error) {
}
if !fi.IsDir() {
return "", fmt.Errorf("cache dir %v is not a directory", cachedir)
return "", errors.Errorf("cache dir %v is not a directory", cachedir)
}
return cachedir, nil
}
@ -284,7 +283,7 @@ func getXDGCacheDir() (string, error) {
}
if !fi.IsDir() {
return "", fmt.Errorf("cache dir %v is not a directory", cachedir)
return "", errors.Errorf("cache dir %v is not a directory", cachedir)
}
return cachedir, nil

View File

@ -2,7 +2,6 @@ package checker
import (
"bytes"
"errors"
"fmt"
"sync"
@ -128,7 +127,7 @@ func (c *Checker) LoadIndex() (hints []error, errs []error) {
debug.Log("LoadIndex", "process index %v", res.ID)
idxID, err := backend.ParseID(res.ID)
if err != nil {
errs = append(errs, fmt.Errorf("unable to parse as index ID: %v", res.ID))
errs = append(errs, errors.Errorf("unable to parse as index ID: %v", res.ID))
continue
}
@ -283,7 +282,7 @@ func loadTreeFromSnapshot(repo *repository.Repository, id backend.ID) (backend.I
if sn.Tree == nil {
debug.Log("Checker.loadTreeFromSnapshot", "snapshot %v has no tree", id.Str())
return backend.ID{}, fmt.Errorf("snapshot %v has no tree", id)
return backend.ID{}, errors.Errorf("snapshot %v has no tree", id)
}
return *sn.Tree, nil
@ -585,24 +584,24 @@ func (c *Checker) checkTree(id backend.ID, tree *restic.Tree) (errs []error) {
switch node.Type {
case "file":
if node.Content == nil {
errs = append(errs, Error{TreeID: id, Err: fmt.Errorf("file %q has nil blob list", node.Name)})
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("file %q has nil blob list", node.Name)})
}
for b, blobID := range node.Content {
if blobID.IsNull() {
errs = append(errs, Error{TreeID: id, Err: fmt.Errorf("file %q blob %d has null ID", node.Name, b)})
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("file %q blob %d has null ID", node.Name, b)})
continue
}
blobs = append(blobs, blobID)
}
case "dir":
if node.Subtree == nil {
errs = append(errs, Error{TreeID: id, Err: fmt.Errorf("dir node %q has no subtree", node.Name)})
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("dir node %q has no subtree", node.Name)})
continue
}
if node.Subtree.IsNull() {
errs = append(errs, Error{TreeID: id, Err: fmt.Errorf("dir node %q subtree id is null", node.Name)})
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("dir node %q subtree id is null", node.Name)})
continue
}
@ -610,7 +609,7 @@ func (c *Checker) checkTree(id backend.ID, tree *restic.Tree) (errs []error) {
// nothing to check
default:
errs = append(errs, Error{TreeID: id, Err: fmt.Errorf("node %q with invalid type %q", node.Name, node.Type)})
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("node %q with invalid type %q", node.Name, node.Type)})
}
if node.Name == "" {
@ -672,7 +671,7 @@ func checkPack(r *repository.Repository, id backend.ID) error {
hash := backend.Hash(buf)
if !hash.Equal(id) {
debug.Log("Checker.checkPack", "Pack ID does not match, want %v, got %v", id.Str(), hash.Str())
return fmt.Errorf("Pack ID does not match, want %v, got %v", id.Str(), hash.Str())
return errors.Errorf("Pack ID does not match, want %v, got %v", id.Str(), hash.Str())
}
blobs, err := pack.List(r.Key(), bytes.NewReader(buf), int64(len(buf)))
@ -688,20 +687,20 @@ func checkPack(r *repository.Repository, id backend.ID) error {
plainBuf, err = crypto.Decrypt(r.Key(), plainBuf, buf[blob.Offset:blob.Offset+blob.Length])
if err != nil {
debug.Log("Checker.checkPack", " error decrypting blob %v: %v", blob.ID.Str(), err)
errs = append(errs, fmt.Errorf("blob %v: %v", i, err))
errs = append(errs, errors.Errorf("blob %v: %v", i, err))
continue
}
hash := backend.Hash(plainBuf)
if !hash.Equal(blob.ID) {
debug.Log("Checker.checkPack", " Blob ID does not match, want %v, got %v", blob.ID.Str(), hash.Str())
errs = append(errs, fmt.Errorf("Blob ID does not match, want %v, got %v", blob.ID.Str(), hash.Str()))
errs = append(errs, errors.Errorf("Blob ID does not match, want %v, got %v", blob.ID.Str(), hash.Str()))
continue
}
}
if len(errs) > 0 {
return fmt.Errorf("pack %v contains %v errors: %v", id.Str(), len(errs), errs)
return errors.Errorf("pack %v contains %v errors: %v", id.Str(), len(errs), errs)
}
return nil

View File

@ -2,10 +2,10 @@ package crypto
import (
"crypto/rand"
"fmt"
"time"
sscrypt "github.com/elithrar/simple-scrypt"
"github.com/pkg/errors"
"golang.org/x/crypto/scrypt"
)
@ -51,7 +51,7 @@ func Calibrate(timeout time.Duration, memory int) (KDFParams, error) {
// using the supplied parameters N, R and P and the Salt.
func KDF(p KDFParams, salt []byte, password string) (*Key, error) {
if len(salt) != saltLength {
return nil, fmt.Errorf("scrypt() called with invalid salt bytes (len %d)", len(salt))
return nil, errors.Errorf("scrypt() called with invalid salt bytes (len %d)", len(salt))
}
// make sure we have valid parameters
@ -72,11 +72,11 @@ func KDF(p KDFParams, salt []byte, password string) (*Key, error) {
keybytes := macKeySize + aesKeySize
scryptKeys, err := scrypt.Key([]byte(password), salt, p.N, p.R, p.P, keybytes)
if err != nil {
return nil, fmt.Errorf("error deriving keys from password: %v", err)
return nil, errors.Errorf("error deriving keys from password: %v", err)
}
if len(scryptKeys) != keybytes {
return nil, fmt.Errorf("invalid numbers of bytes expanded from scrypt(): %d", len(scryptKeys))
return nil, errors.Errorf("invalid numbers of bytes expanded from scrypt(): %d", len(scryptKeys))
}
// first 32 byte of scrypt output is the encryption key

View File

@ -181,7 +181,7 @@ func Load(repo types.Repository, p *restic.Progress) (*Index, error) {
// error is returned.
func (idx *Index) AddPack(id backend.ID, size int64, entries []pack.Blob) error {
if _, ok := idx.Packs[id]; ok {
return fmt.Errorf("pack %v already present in the index", id.Str())
return errors.Errorf("pack %v already present in the index", id.Str())
}
idx.Packs[id] = Pack{Size: size, Entries: entries}
@ -204,7 +204,7 @@ func (idx *Index) AddPack(id backend.ID, size int64, entries []pack.Blob) error
// RemovePack deletes a pack from the index.
func (idx *Index) RemovePack(id backend.ID) error {
if _, ok := idx.Packs[id]; !ok {
return fmt.Errorf("pack %v not found in the index", id.Str())
return errors.Errorf("pack %v not found in the index", id.Str())
}
for _, blob := range idx.Packs[id].Entries {
@ -279,7 +279,7 @@ func (idx *Index) FindBlob(h pack.Handle) ([]Location, error) {
for packID := range blob.Packs {
pack, ok := idx.Packs[packID]
if !ok {
return nil, fmt.Errorf("pack %v not found in index", packID.Str())
return nil, errors.Errorf("pack %v not found in index", packID.Str())
}
for _, entry := range pack.Entries {

View File

@ -10,6 +10,8 @@ import (
"syscall"
"time"
"github.com/pkg/errors"
"runtime"
"restic/backend"
@ -137,7 +139,7 @@ func (node *Node) CreateAt(path string, repo *repository.Repository) error {
case "socket":
return nil
default:
return fmt.Errorf("filetype %q not implemented!\n", node.Type)
return errors.Errorf("filetype %q not implemented!\n", node.Type)
}
err := node.restoreMetadata(path)
@ -485,7 +487,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
case "fifo":
case "socket":
default:
err = fmt.Errorf("invalid node type %q", node.Type)
err = errors.Errorf("invalid node type %q", node.Type)
}
return err

View File

@ -182,7 +182,7 @@ func (p *Packer) writeHeader(wr io.Writer) (bytesWritten uint, err error) {
case Tree:
entry.Type = 1
default:
return 0, fmt.Errorf("invalid blob type %v", b.Type)
return 0, errors.Errorf("invalid blob type %v", b.Type)
}
err := binary.Write(wr, binary.LittleEndian, entry)
@ -316,7 +316,7 @@ func List(k *crypto.Key, rd io.ReaderAt, size int64) (entries []Blob, err error)
case 1:
entry.Type = Tree
default:
return nil, fmt.Errorf("invalid type %d", e.Type)
return nil, errors.Errorf("invalid type %d", e.Type)
}
entries = append(entries, entry)

View File

@ -140,7 +140,7 @@ func (idx *Index) Lookup(id backend.ID, tpe pack.BlobType) (blobs []PackedBlob,
}
debug.Log("Index.Lookup", "id %v not found", id.Str())
return nil, fmt.Errorf("id %v not found in index", id)
return nil, errors.Errorf("id %v not found in index", id)
}
// ListPack returns a list of blobs contained in a pack.
@ -327,7 +327,7 @@ func (idx *Index) generatePackList() ([]*packJSON, error) {
if blob.packID.IsNull() {
debug.Log("Index.generatePackList", "blob %v has no packID! (offset %v, length %v)",
h, blob.offset, blob.length)
return nil, fmt.Errorf("unable to serialize index: pack for blob %v hasn't been written yet", h)
return nil, errors.Errorf("unable to serialize index: pack for blob %v hasn't been written yet", h)
}
// see if pack is already in map

View File

@ -1,9 +1,10 @@
package repository
import (
"fmt"
"sync"
"github.com/pkg/errors"
"restic/backend"
"restic/debug"
"restic/pack"
@ -37,7 +38,7 @@ func (mi *MasterIndex) Lookup(id backend.ID, tpe pack.BlobType) (blobs []PackedB
}
debug.Log("MasterIndex.Lookup", "id %v not found in any index", id.Str())
return nil, fmt.Errorf("id %v not found in any index", id)
return nil, errors.Errorf("id %v not found in any index", id)
}
// LookupSize queries all known Indexes for the ID and returns the first match.
@ -52,7 +53,7 @@ func (mi *MasterIndex) LookupSize(id backend.ID, tpe pack.BlobType) (uint, error
}
}
return 0, fmt.Errorf("id %v not found in any index", id)
return 0, errors.Errorf("id %v not found in any index", id)
}
// ListPack returns the list of blobs in a pack. The first matching index is

View File

@ -1,12 +1,13 @@
package repository
import (
"fmt"
"io"
"io/ioutil"
"os"
"sync"
"github.com/pkg/errors"
"restic/backend"
"restic/crypto"
"restic/debug"
@ -103,7 +104,7 @@ func (r *Repository) savePacker(p *pack.Packer) error {
m, err := io.ReadFull(f, data)
if uint(m) != n {
return fmt.Errorf("read wrong number of bytes from %v: want %v, got %v", tmpfile.Name(), n, m)
return errors.Errorf("read wrong number of bytes from %v: want %v, got %v", tmpfile.Name(), n, m)
}
if err = f.Close(); err != nil {

View File

@ -141,7 +141,7 @@ func (r *Repository) LoadBlob(id backend.ID, t pack.BlobType, plaintextBuf []byt
return plaintextBuf, nil
}
return nil, fmt.Errorf("loading blob %v from %v packs failed", id.Str(), len(blobs))
return nil, errors.Errorf("loading blob %v from %v packs failed", id.Str(), len(blobs))
}
// closeOrErr calls cl.Close() and sets err to the returned error value if
@ -238,7 +238,7 @@ func (r *Repository) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, er
enc := json.NewEncoder(wr)
err := enc.Encode(item)
if err != nil {
return backend.ID{}, fmt.Errorf("json.Encode: %v", err)
return backend.ID{}, errors.Errorf("json.Encode: %v", err)
}
buf = wr.Bytes()
@ -251,7 +251,7 @@ func (r *Repository) SaveJSONUnpacked(t backend.Type, item interface{}) (backend
debug.Log("Repo.SaveJSONUnpacked", "save new blob %v", t)
plaintext, err := json.Marshal(item)
if err != nil {
return backend.ID{}, fmt.Errorf("json.Encode: %v", err)
return backend.ID{}, errors.Errorf("json.Encode: %v", err)
}
return r.SaveUnpacked(t, plaintext)

View File

@ -1,10 +1,11 @@
package restic
import (
"fmt"
"os"
"path/filepath"
"github.com/pkg/errors"
"restic/backend"
"restic/debug"
"restic/fs"
@ -59,7 +60,7 @@ func (res *Restorer) restoreTo(dst string, dir string, treeID backend.ID) error
if node.Type == "dir" {
if node.Subtree == nil {
return fmt.Errorf("Dir without subtree in tree %v", treeID.Str())
return errors.Errorf("Dir without subtree in tree %v", treeID.Str())
}
subp := filepath.Join(dir, node.Name)

View File

@ -141,7 +141,7 @@ func FindLatestSnapshot(repo *repository.Repository, targets []string, source st
for snapshotID := range repo.List(backend.Snapshot, make(chan struct{})) {
snapshot, err := LoadSnapshot(repo, snapshotID)
if err != nil {
return backend.ID{}, fmt.Errorf("Error listing snapshot: %v", err)
return backend.ID{}, errors.Errorf("Error listing snapshot: %v", err)
}
if snapshot.Time.After(latest) && SamePaths(snapshot.Paths, targets) && (source == "" || source == snapshot.Hostname) {
latest = snapshot.Time