From 97619e743cbbfb4e99796ca623bebde247608ffb Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 2 May 2015 01:29:54 +0200 Subject: [PATCH] replace github.com/juju/arrar by /errors --- archiver.go | 6 +++--- node.go | 34 +++++++++++++++++----------------- restorer.go | 30 ++++++++++++++---------------- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/archiver.go b/archiver.go index f1d82b082..a7c1f51e6 100644 --- a/archiver.go +++ b/archiver.go @@ -2,7 +2,6 @@ package restic import ( "encoding/json" - "errors" "fmt" "io" "os" @@ -10,12 +9,13 @@ import ( "sort" "sync" - "github.com/juju/arrar" "github.com/restic/restic/backend" "github.com/restic/restic/debug" "github.com/restic/restic/pack" "github.com/restic/restic/pipe" "github.com/restic/restic/server" + + "github.com/juju/errors" ) const ( @@ -137,7 +137,7 @@ func (arch *Archiver) SaveFile(p *Progress, node *Node) error { } if err != nil { - return arrar.Annotate(err, "SaveFile() chunker.Next()") + return errors.Annotate(err, "Chunker.Next()") } chunks++ diff --git a/node.go b/node.go index 5c9a5768c..39f1da2cb 100644 --- a/node.go +++ b/node.go @@ -10,7 +10,7 @@ import ( "syscall" "time" - "github.com/juju/arrar" + "github.com/juju/errors" "github.com/restic/restic/backend" "github.com/restic/restic/debug" "github.com/restic/restic/pack" @@ -104,27 +104,27 @@ func (node *Node) CreateAt(path string, s *server.Server) error { switch node.Type { case "dir": if err := node.createDirAt(path); err != nil { - return err + return errors.Annotate(err, "createDirAt") } case "file": if err := node.createFileAt(path, s); err != nil { - return err + return errors.Annotate(err, "createFileAt") } case "symlink": if err := node.createSymlinkAt(path); err != nil { - return err + return errors.Annotate(err, "createSymlinkAt") } case "dev": if err := node.createDevAt(path); err != nil { - return arrar.Annotate(err, "Mknod") + return errors.Annotate(err, "createDevAt") } case "chardev": if err := node.createCharDevAt(path); err != nil { - return arrar.Annotate(err, "Mknod") + return errors.Annotate(err, "createCharDevAt") } case "fifo": if err := node.createFifoAt(path); err != nil { - return arrar.Annotate(err, "Mkfifo") + return errors.Annotate(err, "createFifoAt") } case "socket": return nil @@ -140,7 +140,7 @@ func (node Node) restoreMetadata(path string) error { err = os.Lchown(path, int(node.UID), int(node.GID)) if err != nil { - return arrar.Annotate(err, "Lchown") + return errors.Annotate(err, "Lchown") } if node.Type == "symlink" { @@ -149,7 +149,7 @@ func (node Node) restoreMetadata(path string) error { err = os.Chmod(path, node.Mode) if err != nil { - return arrar.Annotate(err, "Chmod") + return errors.Annotate(err, "Chmod") } var utimes = []syscall.Timespec{ @@ -158,7 +158,7 @@ func (node Node) restoreMetadata(path string) error { } err = syscall.UtimesNano(path, utimes) if err != nil { - return arrar.Annotate(err, "Utimesnano") + return errors.Annotate(err, "UtimesNano") } return nil @@ -167,7 +167,7 @@ func (node Node) restoreMetadata(path string) error { func (node Node) createDirAt(path string) error { err := os.Mkdir(path, node.Mode) if err != nil { - return arrar.Annotate(err, "Mkdir") + return errors.Annotate(err, "Mkdir") } return nil @@ -178,18 +178,18 @@ func (node Node) createFileAt(path string, s *server.Server) error { defer f.Close() if err != nil { - return arrar.Annotate(err, "OpenFile") + return errors.Annotate(err, "OpenFile") } for _, id := range node.Content { buf, err := s.LoadBlob(pack.Data, id) if err != nil { - return arrar.Annotate(err, "Load") + return errors.Annotate(err, "Load") } _, err = f.Write(buf) if err != nil { - return arrar.Annotate(err, "Write") + return errors.Annotate(err, "Write") } } @@ -199,7 +199,7 @@ func (node Node) createFileAt(path string, s *server.Server) error { func (node Node) createSymlinkAt(path string) error { err := os.Symlink(node.LinkTarget, path) if err != nil { - return arrar.Annotate(err, "Symlink") + return errors.Annotate(err, "Symlink") } return nil @@ -342,7 +342,7 @@ func (node *Node) fillUser(stat *syscall.Stat_t) error { username, err := lookupUsername(strconv.Itoa(int(stat.Uid))) if err != nil { - return err + return errors.Annotate(err, "fillUser") } node.User = username @@ -388,7 +388,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error { var err error if err = node.fillUser(stat); err != nil { - return err + return errors.Annotate(err, "fillExtra") } switch node.Type { diff --git a/restorer.go b/restorer.go index 93acbbdf4..740677473 100644 --- a/restorer.go +++ b/restorer.go @@ -6,9 +6,10 @@ import ( "path/filepath" "syscall" - "github.com/juju/arrar" "github.com/restic/restic/backend" "github.com/restic/restic/server" + + "github.com/juju/errors" ) type Restorer struct { @@ -29,7 +30,7 @@ func NewRestorer(s *server.Server, id backend.ID) (*Restorer, error) { r.sn, err = LoadSnapshot(s, id) if err != nil { - return nil, arrar.Annotate(err, "load snapshot for restorer") + return nil, errors.Annotate(err, "load snapshot for restorer") } return r, nil @@ -38,7 +39,7 @@ func NewRestorer(s *server.Server, id backend.ID) (*Restorer, error) { func (res *Restorer) restoreTo(dst string, dir string, treeID backend.ID) error { tree, err := LoadTree(res.s, treeID) if err != nil { - return res.Error(dir, nil, arrar.Annotate(err, "LoadTree")) + return res.Error(dir, nil, errors.Annotate(err, "LoadTree")) } for _, node := range tree.Nodes { @@ -54,7 +55,7 @@ func (res *Restorer) restoreTo(dst string, dir string, treeID backend.ID) error subp := filepath.Join(dir, node.Name) err = res.restoreTo(dst, subp, node.Subtree) if err != nil { - err = res.Error(subp, node, arrar.Annotate(err, "restore subtree")) + err = res.Error(subp, node, errors.Annotate(err, "restore subtree")) if err != nil { return err } @@ -75,22 +76,19 @@ func (res *Restorer) restoreNodeTo(node *Node, dir string, dst string) error { err := node.CreateAt(dstPath, res.s) // Did it fail because of ENOENT? - if arrar.Check(err, func(err error) bool { - if pe, ok := err.(*os.PathError); ok { - errn, ok := pe.Err.(syscall.Errno) - return ok && errn == syscall.ENOENT - } - return false - }) { - // Create parent directories and retry - err = os.MkdirAll(filepath.Dir(dstPath), 0700) - if err == nil || err == os.ErrExist { - err = node.CreateAt(dstPath, res.s) + if pe, ok := errors.Cause(err).(*os.PathError); ok { + errn, ok := pe.Err.(syscall.Errno) + if ok && errn == syscall.ENOENT { + // Create parent directories and retry + err = os.MkdirAll(filepath.Dir(dstPath), 0700) + if err == nil || err == os.ErrExist { + err = node.CreateAt(dstPath, res.s) + } } } if err != nil { - err = res.Error(dstPath, node, arrar.Annotate(err, "create node")) + err = res.Error(dstPath, node, errors.Annotate(err, "create node")) if err != nil { return err }