forked from TrueCloudLab/restic
Replace fmt.Errorf() by errors.Errorf()
This commit is contained in:
parent
444a268ce0
commit
72aa6be38d
34 changed files with 100 additions and 92 deletions
|
@ -240,7 +240,7 @@ func filterExisting(items []string) (result []string, err error) {
|
||||||
|
|
||||||
func (cmd CmdBackup) readFromStdin(args []string) error {
|
func (cmd CmdBackup) readFromStdin(args []string) error {
|
||||||
if len(args) != 0 {
|
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()
|
repo, err := cmd.global.OpenRepository()
|
||||||
|
@ -274,7 +274,7 @@ func (cmd CmdBackup) Execute(args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) == 0 {
|
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))
|
target := make([]string, 0, len(args))
|
||||||
|
@ -312,7 +312,7 @@ func (cmd CmdBackup) Execute(args []string) error {
|
||||||
if !cmd.Force && cmd.Parent != "" {
|
if !cmd.Force && cmd.Parent != "" {
|
||||||
id, err := restic.FindSnapshot(repo, cmd.Parent)
|
id, err := restic.FindSnapshot(repo, cmd.Parent)
|
||||||
if err != nil {
|
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
|
parentSnapshotID = &id
|
||||||
|
|
|
@ -26,7 +26,7 @@ func (cmd CmdCache) Usage() string {
|
||||||
|
|
||||||
func (cmd CmdCache) Execute(args []string) error {
|
func (cmd CmdCache) Execute(args []string) error {
|
||||||
// if len(args) == 0 || len(args) > 2 {
|
// 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()
|
repo, err := cmd.global.OpenRepository()
|
||||||
|
|
|
@ -34,7 +34,7 @@ func (cmd CmdCat) Usage() string {
|
||||||
|
|
||||||
func (cmd CmdCat) Execute(args []string) error {
|
func (cmd CmdCat) Execute(args []string) error {
|
||||||
if len(args) < 1 || (args[0] != "masterkey" && args[0] != "config" && len(args) != 2) {
|
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()
|
repo, err := cmd.global.OpenRepository()
|
||||||
|
|
|
@ -105,7 +105,7 @@ func (cmd CmdCheck) Execute(args []string) error {
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
cmd.global.Warnf("error: %v\n", err)
|
cmd.global.Warnf("error: %v\n", err)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("LoadIndex returned errors")
|
return errors.Errorf("LoadIndex returned errors")
|
||||||
}
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
|
@ -204,7 +204,7 @@ func (cmd CmdDump) DumpIndexes() error {
|
||||||
|
|
||||||
func (cmd CmdDump) Execute(args []string) error {
|
func (cmd CmdDump) Execute(args []string) error {
|
||||||
if len(args) != 1 {
|
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()
|
repo, err := cmd.global.OpenRepository()
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"restic"
|
"restic"
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
"restic/debug"
|
"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) {
|
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 {
|
func (c CmdFind) Execute(args []string) error {
|
||||||
if len(args) != 1 {
|
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
|
var err error
|
||||||
|
@ -177,7 +178,7 @@ func (c CmdFind) Execute(args []string) error {
|
||||||
if c.Snapshot != "" {
|
if c.Snapshot != "" {
|
||||||
snapshotID, err := restic.FindSnapshot(repo, c.Snapshot)
|
snapshotID, err := restic.FindSnapshot(repo, c.Snapshot)
|
||||||
if err != nil {
|
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)
|
return c.findInSnapshot(repo, snapshotID)
|
||||||
|
|
|
@ -70,7 +70,7 @@ func (cmd CmdKey) getNewPassword() string {
|
||||||
func (cmd CmdKey) addKey(repo *repository.Repository) error {
|
func (cmd CmdKey) addKey(repo *repository.Repository) error {
|
||||||
id, err := repository.AddKey(repo, cmd.getNewPassword(), repo.Key())
|
id, err := repository.AddKey(repo, cmd.getNewPassword(), repo.Key())
|
||||||
if err != nil {
|
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)
|
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 {
|
func (cmd CmdKey) changePassword(repo *repository.Repository) error {
|
||||||
id, err := repository.AddKey(repo, cmd.getNewPassword(), repo.Key())
|
id, err := repository.AddKey(repo, cmd.getNewPassword(), repo.Key())
|
||||||
if err != nil {
|
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())
|
err = repo.Backend().Remove(backend.Key, repo.KeyName())
|
||||||
|
@ -114,7 +114,7 @@ func (cmd CmdKey) Usage() string {
|
||||||
|
|
||||||
func (cmd CmdKey) Execute(args []string) error {
|
func (cmd CmdKey) Execute(args []string) error {
|
||||||
if len(args) < 1 || (args[0] == "rm" && len(args) != 2) {
|
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()
|
repo, err := cmd.global.OpenRepository()
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
|
@ -28,7 +26,7 @@ func (cmd CmdList) Usage() string {
|
||||||
|
|
||||||
func (cmd CmdList) Execute(args []string) error {
|
func (cmd CmdList) Execute(args []string) error {
|
||||||
if len(args) != 1 {
|
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()
|
repo, err := cmd.global.OpenRepository()
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"restic"
|
"restic"
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
"restic/repository"
|
"restic/repository"
|
||||||
|
@ -72,7 +74,7 @@ func (cmd CmdLs) Usage() string {
|
||||||
|
|
||||||
func (cmd CmdLs) Execute(args []string) error {
|
func (cmd CmdLs) Execute(args []string) error {
|
||||||
if len(args) < 1 || len(args) > 2 {
|
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()
|
repo, err := cmd.global.OpenRepository()
|
||||||
|
|
|
@ -4,9 +4,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
resticfs "restic/fs"
|
resticfs "restic/fs"
|
||||||
"restic/fuse"
|
"restic/fuse"
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ func (cmd CmdMount) Usage() string {
|
||||||
|
|
||||||
func (cmd CmdMount) Execute(args []string) error {
|
func (cmd CmdMount) Execute(args []string) error {
|
||||||
if len(args) == 0 {
|
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()
|
repo, err := cmd.global.OpenRepository()
|
||||||
|
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"restic/repository"
|
"restic/repository"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -191,7 +193,7 @@ nextPack:
|
||||||
removePacks.Insert(packID)
|
removePacks.Insert(packID)
|
||||||
|
|
||||||
if !rewritePacks.Has(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)
|
rewritePacks.Delete(packID)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"restic"
|
"restic"
|
||||||
|
@ -37,7 +35,7 @@ func (cmd CmdRestore) Usage() string {
|
||||||
|
|
||||||
func (cmd CmdRestore) Execute(args []string) error {
|
func (cmd CmdRestore) Execute(args []string) error {
|
||||||
if len(args) != 1 {
|
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 == "" {
|
if cmd.Target == "" {
|
||||||
|
|
|
@ -8,6 +8,8 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"restic"
|
"restic"
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
)
|
)
|
||||||
|
@ -70,7 +72,7 @@ func (cmd CmdSnapshots) Usage() string {
|
||||||
|
|
||||||
func (cmd CmdSnapshots) Execute(args []string) error {
|
func (cmd CmdSnapshots) Execute(args []string) error {
|
||||||
if len(args) != 0 {
|
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()
|
repo, err := cmd.global.OpenRepository()
|
||||||
|
|
|
@ -263,7 +263,7 @@ func (o GlobalOptions) OpenRepository() (*repository.Repository, error) {
|
||||||
|
|
||||||
err = s.SearchKey(o.password, maxKeys)
|
err = s.SearchKey(o.password, maxKeys)
|
||||||
if err != nil {
|
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
|
return s, nil
|
||||||
|
@ -301,7 +301,7 @@ func open(s string) (backend.Backend, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
debug.Log("open", "invalid repository location: %v", s)
|
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.
|
// 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)
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"restic"
|
"restic"
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
"restic/repository"
|
"restic/repository"
|
||||||
|
@ -50,7 +51,7 @@ func waitForMount(dir string) error {
|
||||||
time.Sleep(mountSleep)
|
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{}) {
|
func cmdMount(t testing.TB, global GlobalOptions, dir string, ready, done chan struct{}) {
|
||||||
|
|
|
@ -15,6 +15,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
"restic/debug"
|
"restic/debug"
|
||||||
"restic/filter"
|
"restic/filter"
|
||||||
|
@ -579,7 +581,7 @@ func testFileSize(filename string, size int64) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.Size() != size {
|
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
|
return nil
|
||||||
|
|
|
@ -178,7 +178,7 @@ func waitForResults(resultChannels [](<-chan saveResult)) ([]saveResult, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(results) != len(resultChannels) {
|
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
|
return results, nil
|
||||||
|
@ -198,7 +198,7 @@ func updateNodeContent(node *Node, results []saveResult) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes != node.Size {
|
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))
|
debug.Log("Archiver.SaveFile", "SaveFile(%q): %v blobs\n", node.path, len(results))
|
||||||
|
|
|
@ -34,7 +34,7 @@ func (h Handle) Valid() error {
|
||||||
case Index:
|
case Index:
|
||||||
case Config:
|
case Config:
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid Type %q", h.Type)
|
return errors.Errorf("invalid Type %q", h.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.Type == Config {
|
if h.Type == Config {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package local
|
package local
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -36,7 +35,7 @@ func Open(dir string) (*Local, error) {
|
||||||
// test if all necessary dirs are there
|
// test if all necessary dirs are there
|
||||||
for _, d := range paths(dir) {
|
for _, d := range paths(dir) {
|
||||||
if _, err := fs.Stat(d); err != nil {
|
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
|
// test if new path already exists
|
||||||
if _, err := fs.Stat(filename); err == nil {
|
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
|
// create directories if necessary, ignore errors
|
||||||
|
|
|
@ -113,7 +113,7 @@ func (b *restBackend) Load(h backend.Handle, p []byte, off int64) (n int, err er
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if resp.StatusCode != 200 && resp.StatusCode != 206 {
|
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)
|
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 {
|
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
|
return nil
|
||||||
|
@ -168,7 +168,7 @@ func (b *restBackend) Stat(h backend.Handle) (backend.BlobInfo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
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 {
|
if resp.ContentLength < 0 {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package sftp
|
package sftp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -35,7 +34,7 @@ func ParseConfig(s string) (interface{}, error) {
|
||||||
host = url.Host
|
host = url.Host
|
||||||
dir = url.Path
|
dir = url.Path
|
||||||
if dir == "" {
|
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:]
|
dir = dir[1:]
|
||||||
|
|
|
@ -80,7 +80,7 @@ func startClient(program string, args ...string) (*SFTP, error) {
|
||||||
// open the SFTP session
|
// open the SFTP session
|
||||||
client, err := sftp.NewClientPipe(rd, wr)
|
client, err := sftp.NewClientPipe(rd, wr)
|
||||||
if err != nil {
|
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
|
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
|
// test if all necessary dirs and files are there
|
||||||
for _, d := range paths(dir) {
|
for _, d := range paths(dir) {
|
||||||
if _, err := sftp.c.Lstat(d); err != nil {
|
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)
|
buf := make([]byte, tempfileRandomSuffixLength)
|
||||||
_, err := io.ReadFull(rand.Reader, buf)
|
_, err := io.ReadFull(rand.Reader, buf)
|
||||||
if err != nil {
|
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)
|
tempfileRandomSuffixLength, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ func (r *SFTP) tempFile() (string, *sftp.File, error) {
|
||||||
// create file in temp dir
|
// create file in temp dir
|
||||||
f, err := r.c.Create(name)
|
f, err := r.c.Create(name)
|
||||||
if err != nil {
|
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
|
return name, f, nil
|
||||||
|
@ -231,7 +231,7 @@ func (r *SFTP) mkdirAll(dir string, mode os.FileMode) error {
|
||||||
return nil
|
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
|
// create parent directories
|
||||||
|
@ -244,11 +244,11 @@ func (r *SFTP) mkdirAll(dir string, mode os.FileMode) error {
|
||||||
fi, err = r.c.Lstat(dir)
|
fi, err = r.c.Lstat(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// return previous errors
|
// 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() {
|
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
|
// set mode
|
||||||
|
@ -269,7 +269,7 @@ func (r *SFTP) renameFile(oldname string, t backend.Type, name string) error {
|
||||||
|
|
||||||
// test if new file exists
|
// test if new file exists
|
||||||
if _, err := r.c.Lstat(filename); err == nil {
|
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)
|
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",
|
debug.Log("sftp.Save", "save %v: rename %v: %v",
|
||||||
h, path.Base(filename), err)
|
h, path.Base(filename), err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("sftp: renameFile: %v", err)
|
return errors.Errorf("sftp: renameFile: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package restic
|
package restic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -156,7 +155,7 @@ func (c *Cache) list(t backend.Type) ([]cacheEntry, error) {
|
||||||
case backend.Snapshot:
|
case backend.Snapshot:
|
||||||
dir = filepath.Join(c.base, "snapshots")
|
dir = filepath.Join(c.base, "snapshots")
|
||||||
default:
|
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)
|
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 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) {
|
func getCacheDir() (string, error) {
|
||||||
|
@ -246,7 +245,7 @@ func getWindowsCacheDir() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !fi.IsDir() {
|
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
|
return cachedir, nil
|
||||||
}
|
}
|
||||||
|
@ -284,7 +283,7 @@ func getXDGCacheDir() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !fi.IsDir() {
|
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
|
return cachedir, nil
|
||||||
|
|
|
@ -2,7 +2,6 @@ package checker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -128,7 +127,7 @@ func (c *Checker) LoadIndex() (hints []error, errs []error) {
|
||||||
debug.Log("LoadIndex", "process index %v", res.ID)
|
debug.Log("LoadIndex", "process index %v", res.ID)
|
||||||
idxID, err := backend.ParseID(res.ID)
|
idxID, err := backend.ParseID(res.ID)
|
||||||
if err != nil {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +282,7 @@ func loadTreeFromSnapshot(repo *repository.Repository, id backend.ID) (backend.I
|
||||||
|
|
||||||
if sn.Tree == nil {
|
if sn.Tree == nil {
|
||||||
debug.Log("Checker.loadTreeFromSnapshot", "snapshot %v has no tree", id.Str())
|
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
|
return *sn.Tree, nil
|
||||||
|
@ -585,24 +584,24 @@ func (c *Checker) checkTree(id backend.ID, tree *restic.Tree) (errs []error) {
|
||||||
switch node.Type {
|
switch node.Type {
|
||||||
case "file":
|
case "file":
|
||||||
if node.Content == nil {
|
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 {
|
for b, blobID := range node.Content {
|
||||||
if blobID.IsNull() {
|
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
|
continue
|
||||||
}
|
}
|
||||||
blobs = append(blobs, blobID)
|
blobs = append(blobs, blobID)
|
||||||
}
|
}
|
||||||
case "dir":
|
case "dir":
|
||||||
if node.Subtree == nil {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if node.Subtree.IsNull() {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,7 +609,7 @@ func (c *Checker) checkTree(id backend.ID, tree *restic.Tree) (errs []error) {
|
||||||
// nothing to check
|
// nothing to check
|
||||||
|
|
||||||
default:
|
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 == "" {
|
if node.Name == "" {
|
||||||
|
@ -672,7 +671,7 @@ func checkPack(r *repository.Repository, id backend.ID) error {
|
||||||
hash := backend.Hash(buf)
|
hash := backend.Hash(buf)
|
||||||
if !hash.Equal(id) {
|
if !hash.Equal(id) {
|
||||||
debug.Log("Checker.checkPack", "Pack ID does not match, want %v, got %v", id.Str(), hash.Str())
|
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)))
|
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])
|
plainBuf, err = crypto.Decrypt(r.Key(), plainBuf, buf[blob.Offset:blob.Offset+blob.Length])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Log("Checker.checkPack", " error decrypting blob %v: %v", blob.ID.Str(), err)
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
hash := backend.Hash(plainBuf)
|
hash := backend.Hash(plainBuf)
|
||||||
if !hash.Equal(blob.ID) {
|
if !hash.Equal(blob.ID) {
|
||||||
debug.Log("Checker.checkPack", " Blob ID does not match, want %v, got %v", blob.ID.Str(), hash.Str())
|
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
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
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
|
return nil
|
||||||
|
|
|
@ -2,10 +2,10 @@ package crypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
sscrypt "github.com/elithrar/simple-scrypt"
|
sscrypt "github.com/elithrar/simple-scrypt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/crypto/scrypt"
|
"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.
|
// using the supplied parameters N, R and P and the Salt.
|
||||||
func KDF(p KDFParams, salt []byte, password string) (*Key, error) {
|
func KDF(p KDFParams, salt []byte, password string) (*Key, error) {
|
||||||
if len(salt) != saltLength {
|
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
|
// make sure we have valid parameters
|
||||||
|
@ -72,11 +72,11 @@ func KDF(p KDFParams, salt []byte, password string) (*Key, error) {
|
||||||
keybytes := macKeySize + aesKeySize
|
keybytes := macKeySize + aesKeySize
|
||||||
scryptKeys, err := scrypt.Key([]byte(password), salt, p.N, p.R, p.P, keybytes)
|
scryptKeys, err := scrypt.Key([]byte(password), salt, p.N, p.R, p.P, keybytes)
|
||||||
if err != nil {
|
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 {
|
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
|
// first 32 byte of scrypt output is the encryption key
|
||||||
|
|
|
@ -181,7 +181,7 @@ func Load(repo types.Repository, p *restic.Progress) (*Index, error) {
|
||||||
// error is returned.
|
// error is returned.
|
||||||
func (idx *Index) AddPack(id backend.ID, size int64, entries []pack.Blob) error {
|
func (idx *Index) AddPack(id backend.ID, size int64, entries []pack.Blob) error {
|
||||||
if _, ok := idx.Packs[id]; ok {
|
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}
|
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.
|
// RemovePack deletes a pack from the index.
|
||||||
func (idx *Index) RemovePack(id backend.ID) error {
|
func (idx *Index) RemovePack(id backend.ID) error {
|
||||||
if _, ok := idx.Packs[id]; !ok {
|
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 {
|
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 {
|
for packID := range blob.Packs {
|
||||||
pack, ok := idx.Packs[packID]
|
pack, ok := idx.Packs[packID]
|
||||||
if !ok {
|
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 {
|
for _, entry := range pack.Entries {
|
||||||
|
|
|
@ -10,6 +10,8 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
|
@ -137,7 +139,7 @@ func (node *Node) CreateAt(path string, repo *repository.Repository) error {
|
||||||
case "socket":
|
case "socket":
|
||||||
return nil
|
return nil
|
||||||
default:
|
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)
|
err := node.restoreMetadata(path)
|
||||||
|
@ -485,7 +487,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
|
||||||
case "fifo":
|
case "fifo":
|
||||||
case "socket":
|
case "socket":
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("invalid node type %q", node.Type)
|
err = errors.Errorf("invalid node type %q", node.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -182,7 +182,7 @@ func (p *Packer) writeHeader(wr io.Writer) (bytesWritten uint, err error) {
|
||||||
case Tree:
|
case Tree:
|
||||||
entry.Type = 1
|
entry.Type = 1
|
||||||
default:
|
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)
|
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:
|
case 1:
|
||||||
entry.Type = Tree
|
entry.Type = Tree
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("invalid type %d", e.Type)
|
return nil, errors.Errorf("invalid type %d", e.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
entries = append(entries, entry)
|
entries = append(entries, entry)
|
||||||
|
|
|
@ -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())
|
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.
|
// ListPack returns a list of blobs contained in a pack.
|
||||||
|
@ -327,7 +327,7 @@ func (idx *Index) generatePackList() ([]*packJSON, error) {
|
||||||
if blob.packID.IsNull() {
|
if blob.packID.IsNull() {
|
||||||
debug.Log("Index.generatePackList", "blob %v has no packID! (offset %v, length %v)",
|
debug.Log("Index.generatePackList", "blob %v has no packID! (offset %v, length %v)",
|
||||||
h, blob.offset, blob.length)
|
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
|
// see if pack is already in map
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
"restic/debug"
|
"restic/debug"
|
||||||
"restic/pack"
|
"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())
|
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.
|
// 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
|
// ListPack returns the list of blobs in a pack. The first matching index is
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
"restic/crypto"
|
"restic/crypto"
|
||||||
"restic/debug"
|
"restic/debug"
|
||||||
|
@ -103,7 +104,7 @@ func (r *Repository) savePacker(p *pack.Packer) error {
|
||||||
m, err := io.ReadFull(f, data)
|
m, err := io.ReadFull(f, data)
|
||||||
|
|
||||||
if uint(m) != n {
|
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 {
|
if err = f.Close(); err != nil {
|
||||||
|
|
|
@ -141,7 +141,7 @@ func (r *Repository) LoadBlob(id backend.ID, t pack.BlobType, plaintextBuf []byt
|
||||||
return plaintextBuf, nil
|
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
|
// 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)
|
enc := json.NewEncoder(wr)
|
||||||
err := enc.Encode(item)
|
err := enc.Encode(item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return backend.ID{}, fmt.Errorf("json.Encode: %v", err)
|
return backend.ID{}, errors.Errorf("json.Encode: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = wr.Bytes()
|
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)
|
debug.Log("Repo.SaveJSONUnpacked", "save new blob %v", t)
|
||||||
plaintext, err := json.Marshal(item)
|
plaintext, err := json.Marshal(item)
|
||||||
if err != nil {
|
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)
|
return r.SaveUnpacked(t, plaintext)
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package restic
|
package restic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
"restic/debug"
|
"restic/debug"
|
||||||
"restic/fs"
|
"restic/fs"
|
||||||
|
@ -59,7 +60,7 @@ func (res *Restorer) restoreTo(dst string, dir string, treeID backend.ID) error
|
||||||
|
|
||||||
if node.Type == "dir" {
|
if node.Type == "dir" {
|
||||||
if node.Subtree == nil {
|
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)
|
subp := filepath.Join(dir, node.Name)
|
||||||
|
|
|
@ -141,7 +141,7 @@ func FindLatestSnapshot(repo *repository.Repository, targets []string, source st
|
||||||
for snapshotID := range repo.List(backend.Snapshot, make(chan struct{})) {
|
for snapshotID := range repo.List(backend.Snapshot, make(chan struct{})) {
|
||||||
snapshot, err := LoadSnapshot(repo, snapshotID)
|
snapshot, err := LoadSnapshot(repo, snapshotID)
|
||||||
if err != nil {
|
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) {
|
if snapshot.Time.After(latest) && SamePaths(snapshot.Paths, targets) && (source == "" || source == snapshot.Hostname) {
|
||||||
latest = snapshot.Time
|
latest = snapshot.Time
|
||||||
|
|
Loading…
Reference in a new issue