From b8ce1b4e69301209fcb57ffd004ac34e3dc35c0a Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 18 Feb 2017 17:46:06 +0100 Subject: [PATCH] Correct archiver behavior in case of errors --- src/restic/archiver/archiver.go | 22 +++++++++++----------- src/restic/node.go | 3 ++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/restic/archiver/archiver.go b/src/restic/archiver/archiver.go index 3412f4b35..6a5b84a31 100644 --- a/src/restic/archiver/archiver.go +++ b/src/restic/archiver/archiver.go @@ -142,7 +142,7 @@ func (arch *Archiver) reloadFileIfChanged(node *restic.Node, file fs.File) (*res node, err = restic.NodeFromFileInfo(node.Path, fi) if err != nil { debug.Log("restic.NodeFromFileInfo returned error for %v: %v", node.Path, err) - return nil, err + arch.Warn(node.Path, fi, err) } 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()) if err != nil { - // TODO: integrate error reporting debug.Log("restic.NodeFromFileInfo returned error for %v: %v", node.Path, err) - e.Result() <- nil - p.Report(restic.Stat{Errors: 1}) - continue + arch.Warn(e.Fullpath(), e.Info(), err) } // 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 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) if err != nil { - // TODO: integrate error reporting fmt.Fprintf(os.Stderr, "error for %v: %v\n", node.Path, err) + arch.Warn(e.Path(), nil, err) // ignore this file e.Result() <- nil 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 node := res.(*restic.Node) - tree.Insert(node) if node.Type == "dir" { 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() { panic("invalid null subtree restic.ID") } } + tree.Insert(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 { n, err := restic.NodeFromFileInfo(dir.Fullpath(), dir.Info()) if err != nil { - n.Error = err.Error() - dir.Result() <- n - continue + arch.Warn(dir.Path(), dir.Info(), err) } node = n } diff --git a/src/restic/node.go b/src/restic/node.go index 493929dc7..9f416a2a9 100644 --- a/src/restic/node.go +++ b/src/restic/node.go @@ -63,7 +63,8 @@ func (node Node) String() string { return fmt.Sprintf("", 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) { mask := os.ModePerm | os.ModeType | os.ModeSetuid | os.ModeSetgid | os.ModeSticky node := &Node{