2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-02 19:49:44 +00:00

Correct archiver behavior in case of errors

This commit is contained in:
Alexander Neumann 2017-02-18 17:46:06 +01:00
parent 23c2717ab2
commit b8ce1b4e69
2 changed files with 13 additions and 12 deletions

View File

@ -142,7 +142,7 @@ func (arch *Archiver) reloadFileIfChanged(node *restic.Node, file fs.File) (*res
node, err = restic.NodeFromFileInfo(node.Path, fi) node, err = restic.NodeFromFileInfo(node.Path, fi)
if err != nil { if err != nil {
debug.Log("restic.NodeFromFileInfo returned error for %v: %v", node.Path, err) debug.Log("restic.NodeFromFileInfo returned error for %v: %v", node.Path, err)
return nil, err arch.Warn(node.Path, fi, err)
} }
return node, nil return node, nil
@ -275,11 +275,8 @@ func (arch *Archiver) fileWorker(wg *sync.WaitGroup, p *restic.Progress, done <-
node, err := restic.NodeFromFileInfo(e.Fullpath(), e.Info()) node, err := restic.NodeFromFileInfo(e.Fullpath(), e.Info())
if err != nil { if err != nil {
// TODO: integrate error reporting
debug.Log("restic.NodeFromFileInfo returned error for %v: %v", node.Path, err) debug.Log("restic.NodeFromFileInfo returned error for %v: %v", node.Path, err)
e.Result() <- nil arch.Warn(e.Fullpath(), e.Info(), err)
p.Report(restic.Stat{Errors: 1})
continue
} }
// try to use old node, if present // try to use old node, if present
@ -307,11 +304,11 @@ func (arch *Archiver) fileWorker(wg *sync.WaitGroup, p *restic.Progress, done <-
// otherwise read file normally // otherwise read file normally
if node.Type == "file" && len(node.Content) == 0 { if node.Type == "file" && len(node.Content) == 0 {
debug.Log(" read and save %v, content: %v", e.Path(), node.Content) debug.Log(" read and save %v", e.Path())
node, err = arch.SaveFile(p, node) node, err = arch.SaveFile(p, node)
if err != nil { if err != nil {
// TODO: integrate error reporting
fmt.Fprintf(os.Stderr, "error for %v: %v\n", node.Path, err) fmt.Fprintf(os.Stderr, "error for %v: %v\n", node.Path, err)
arch.Warn(e.Path(), nil, err)
// ignore this file // ignore this file
e.Result() <- nil e.Result() <- nil
p.Report(restic.Stat{Errors: 1}) p.Report(restic.Stat{Errors: 1})
@ -371,15 +368,20 @@ func (arch *Archiver) dirWorker(wg *sync.WaitGroup, p *restic.Progress, done <-c
// else insert node // else insert node
node := res.(*restic.Node) node := res.(*restic.Node)
tree.Insert(node)
if node.Type == "dir" { if node.Type == "dir" {
debug.Log("got tree node for %s: %v", node.Path, node.Subtree) debug.Log("got tree node for %s: %v", node.Path, node.Subtree)
if node.Subtree == nil {
debug.Log("subtree is nil for node %v", node.Path)
continue
}
if node.Subtree.IsNull() { if node.Subtree.IsNull() {
panic("invalid null subtree restic.ID") panic("invalid null subtree restic.ID")
} }
} }
tree.Insert(node)
} }
node := &restic.Node{} node := &restic.Node{}
@ -387,9 +389,7 @@ func (arch *Archiver) dirWorker(wg *sync.WaitGroup, p *restic.Progress, done <-c
if dir.Path() != "" && dir.Info() != nil { if dir.Path() != "" && dir.Info() != nil {
n, err := restic.NodeFromFileInfo(dir.Fullpath(), dir.Info()) n, err := restic.NodeFromFileInfo(dir.Fullpath(), dir.Info())
if err != nil { if err != nil {
n.Error = err.Error() arch.Warn(dir.Path(), dir.Info(), err)
dir.Result() <- n
continue
} }
node = n node = n
} }

View File

@ -63,7 +63,8 @@ func (node Node) String() string {
return fmt.Sprintf("<Node(%s) %s>", node.Type, node.Name) return fmt.Sprintf("<Node(%s) %s>", node.Type, node.Name)
} }
// NodeFromFileInfo returns a new node from the given path and FileInfo. // NodeFromFileInfo returns a new node from the given path and FileInfo. It
// returns the first error that is encountered, together with a node.
func NodeFromFileInfo(path string, fi os.FileInfo) (*Node, error) { func NodeFromFileInfo(path string, fi os.FileInfo) (*Node, error) {
mask := os.ModePerm | os.ModeType | os.ModeSetuid | os.ModeSetgid | os.ModeSticky mask := os.ModePerm | os.ModeType | os.ModeSetuid | os.ModeSetgid | os.ModeSticky
node := &Node{ node := &Node{