replace github.com/juju/arrar by /errors

This commit is contained in:
Alexander Neumann 2015-05-02 01:29:54 +02:00
parent 813031a989
commit 97619e743c
3 changed files with 34 additions and 36 deletions

View File

@ -2,7 +2,6 @@ package restic
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -10,12 +9,13 @@ import (
"sort" "sort"
"sync" "sync"
"github.com/juju/arrar"
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/debug" "github.com/restic/restic/debug"
"github.com/restic/restic/pack" "github.com/restic/restic/pack"
"github.com/restic/restic/pipe" "github.com/restic/restic/pipe"
"github.com/restic/restic/server" "github.com/restic/restic/server"
"github.com/juju/errors"
) )
const ( const (
@ -137,7 +137,7 @@ func (arch *Archiver) SaveFile(p *Progress, node *Node) error {
} }
if err != nil { if err != nil {
return arrar.Annotate(err, "SaveFile() chunker.Next()") return errors.Annotate(err, "Chunker.Next()")
} }
chunks++ chunks++

34
node.go
View File

@ -10,7 +10,7 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/juju/arrar" "github.com/juju/errors"
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/debug" "github.com/restic/restic/debug"
"github.com/restic/restic/pack" "github.com/restic/restic/pack"
@ -104,27 +104,27 @@ func (node *Node) CreateAt(path string, s *server.Server) error {
switch node.Type { switch node.Type {
case "dir": case "dir":
if err := node.createDirAt(path); err != nil { if err := node.createDirAt(path); err != nil {
return err return errors.Annotate(err, "createDirAt")
} }
case "file": case "file":
if err := node.createFileAt(path, s); err != nil { if err := node.createFileAt(path, s); err != nil {
return err return errors.Annotate(err, "createFileAt")
} }
case "symlink": case "symlink":
if err := node.createSymlinkAt(path); err != nil { if err := node.createSymlinkAt(path); err != nil {
return err return errors.Annotate(err, "createSymlinkAt")
} }
case "dev": case "dev":
if err := node.createDevAt(path); err != nil { if err := node.createDevAt(path); err != nil {
return arrar.Annotate(err, "Mknod") return errors.Annotate(err, "createDevAt")
} }
case "chardev": case "chardev":
if err := node.createCharDevAt(path); err != nil { if err := node.createCharDevAt(path); err != nil {
return arrar.Annotate(err, "Mknod") return errors.Annotate(err, "createCharDevAt")
} }
case "fifo": case "fifo":
if err := node.createFifoAt(path); err != nil { if err := node.createFifoAt(path); err != nil {
return arrar.Annotate(err, "Mkfifo") return errors.Annotate(err, "createFifoAt")
} }
case "socket": case "socket":
return nil return nil
@ -140,7 +140,7 @@ func (node Node) restoreMetadata(path string) error {
err = os.Lchown(path, int(node.UID), int(node.GID)) err = os.Lchown(path, int(node.UID), int(node.GID))
if err != nil { if err != nil {
return arrar.Annotate(err, "Lchown") return errors.Annotate(err, "Lchown")
} }
if node.Type == "symlink" { if node.Type == "symlink" {
@ -149,7 +149,7 @@ func (node Node) restoreMetadata(path string) error {
err = os.Chmod(path, node.Mode) err = os.Chmod(path, node.Mode)
if err != nil { if err != nil {
return arrar.Annotate(err, "Chmod") return errors.Annotate(err, "Chmod")
} }
var utimes = []syscall.Timespec{ var utimes = []syscall.Timespec{
@ -158,7 +158,7 @@ func (node Node) restoreMetadata(path string) error {
} }
err = syscall.UtimesNano(path, utimes) err = syscall.UtimesNano(path, utimes)
if err != nil { if err != nil {
return arrar.Annotate(err, "Utimesnano") return errors.Annotate(err, "UtimesNano")
} }
return nil return nil
@ -167,7 +167,7 @@ func (node Node) restoreMetadata(path string) error {
func (node Node) createDirAt(path string) error { func (node Node) createDirAt(path string) error {
err := os.Mkdir(path, node.Mode) err := os.Mkdir(path, node.Mode)
if err != nil { if err != nil {
return arrar.Annotate(err, "Mkdir") return errors.Annotate(err, "Mkdir")
} }
return nil return nil
@ -178,18 +178,18 @@ func (node Node) createFileAt(path string, s *server.Server) error {
defer f.Close() defer f.Close()
if err != nil { if err != nil {
return arrar.Annotate(err, "OpenFile") return errors.Annotate(err, "OpenFile")
} }
for _, id := range node.Content { for _, id := range node.Content {
buf, err := s.LoadBlob(pack.Data, id) buf, err := s.LoadBlob(pack.Data, id)
if err != nil { if err != nil {
return arrar.Annotate(err, "Load") return errors.Annotate(err, "Load")
} }
_, err = f.Write(buf) _, err = f.Write(buf)
if err != nil { 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 { func (node Node) createSymlinkAt(path string) error {
err := os.Symlink(node.LinkTarget, path) err := os.Symlink(node.LinkTarget, path)
if err != nil { if err != nil {
return arrar.Annotate(err, "Symlink") return errors.Annotate(err, "Symlink")
} }
return nil return nil
@ -342,7 +342,7 @@ func (node *Node) fillUser(stat *syscall.Stat_t) error {
username, err := lookupUsername(strconv.Itoa(int(stat.Uid))) username, err := lookupUsername(strconv.Itoa(int(stat.Uid)))
if err != nil { if err != nil {
return err return errors.Annotate(err, "fillUser")
} }
node.User = username node.User = username
@ -388,7 +388,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
var err error var err error
if err = node.fillUser(stat); err != nil { if err = node.fillUser(stat); err != nil {
return err return errors.Annotate(err, "fillExtra")
} }
switch node.Type { switch node.Type {

View File

@ -6,9 +6,10 @@ import (
"path/filepath" "path/filepath"
"syscall" "syscall"
"github.com/juju/arrar"
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/server" "github.com/restic/restic/server"
"github.com/juju/errors"
) )
type Restorer struct { type Restorer struct {
@ -29,7 +30,7 @@ func NewRestorer(s *server.Server, id backend.ID) (*Restorer, error) {
r.sn, err = LoadSnapshot(s, id) r.sn, err = LoadSnapshot(s, id)
if err != nil { if err != nil {
return nil, arrar.Annotate(err, "load snapshot for restorer") return nil, errors.Annotate(err, "load snapshot for restorer")
} }
return r, nil 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 { func (res *Restorer) restoreTo(dst string, dir string, treeID backend.ID) error {
tree, err := LoadTree(res.s, treeID) tree, err := LoadTree(res.s, treeID)
if err != nil { 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 { 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) subp := filepath.Join(dir, node.Name)
err = res.restoreTo(dst, subp, node.Subtree) err = res.restoreTo(dst, subp, node.Subtree)
if err != nil { 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 { if err != nil {
return err return err
} }
@ -75,22 +76,19 @@ func (res *Restorer) restoreNodeTo(node *Node, dir string, dst string) error {
err := node.CreateAt(dstPath, res.s) err := node.CreateAt(dstPath, res.s)
// Did it fail because of ENOENT? // Did it fail because of ENOENT?
if arrar.Check(err, func(err error) bool { if pe, ok := errors.Cause(err).(*os.PathError); ok {
if pe, ok := err.(*os.PathError); ok { errn, ok := pe.Err.(syscall.Errno)
errn, ok := pe.Err.(syscall.Errno) if ok && errn == syscall.ENOENT {
return ok && errn == syscall.ENOENT // Create parent directories and retry
} err = os.MkdirAll(filepath.Dir(dstPath), 0700)
return false if err == nil || err == os.ErrExist {
}) { err = node.CreateAt(dstPath, res.s)
// 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 { 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 { if err != nil {
return err return err
} }