Merge branch 'replace_arrar'

This commit is contained in:
Alexander Neumann 2015-05-02 14:34:33 +02:00
commit 4a1cb65645
3 changed files with 34 additions and 36 deletions

View file

@ -2,7 +2,6 @@ package restic
import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
@ -10,13 +9,14 @@ import (
"sort"
"sync"
"github.com/juju/arrar"
"github.com/restic/restic/backend"
"github.com/restic/restic/chunker"
"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 (
@ -192,7 +192,7 @@ func (arch *Archiver) SaveFile(p *Progress, node *Node) error {
}
if err != nil {
return arrar.Annotate(err, "SaveFile() chunker.Next()")
return errors.Annotate(err, "SaveFile() chunker.Next()")
}
resCh := make(chan saveResult, 1)

34
node.go
View file

@ -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 {

View file

@ -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
}