From aca0692ee64528d472feca240abfdc6b0ced9b27 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 21 Mar 2015 14:43:33 +0100 Subject: [PATCH] Add more error reporting --- archiver.go | 16 +++++++++++++++- node_linux.go | 8 +++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/archiver.go b/archiver.go index 6a54f42a1..976eecfe2 100644 --- a/archiver.go +++ b/archiver.go @@ -185,6 +185,7 @@ func (arch *Archiver) SaveFile(p *Progress, node *Node) (Blobs, error) { // create new node n, err := NodeFromFileInfo(node.path, fi) if err != nil { + debug.Log("Archiver.SaveFile", "NodeFromFileInfo returned error for %v: %v", node.path, err) return nil, err } @@ -405,7 +406,11 @@ func (arch *Archiver) fileWorker(wg *sync.WaitGroup, p *Progress, done <-chan st node, err := NodeFromFileInfo(e.Fullpath(), e.Info()) if err != nil { - panic(err) + // TODO: integrate error reporting + debug.Log("Archiver.fileWorker", "NodeFromFileInfo returned error for %v: %v", node.path, err) + e.Result() <- nil + p.Report(Stat{Files: 1}) + continue } // try to use old node, if present @@ -825,6 +830,15 @@ func Scan(dirs []string, p *Progress) (Stat, error) { debug.Log("Scan", "Start for %v", dir) err := filepath.Walk(dir, func(str string, fi os.FileInfo, err error) error { debug.Log("Scan.Walk", "%v, fi: %v, err: %v", str, fi, err) + // TODO: integrate error reporting + if err != nil { + fmt.Fprintf(os.Stderr, "error for %v: %v\n", str, err) + return nil + } + if fi == nil { + fmt.Fprintf(os.Stderr, "error for %v: FileInfo is nil\n", str) + return nil + } s := Stat{} if isFile(fi) { s.Files++ diff --git a/node_linux.go b/node_linux.go index 3ec6653df..a430fa885 100644 --- a/node_linux.go +++ b/node_linux.go @@ -11,10 +11,10 @@ import ( "github.com/restic/restic/debug" ) -func (node *Node) fill_extra(path string, fi os.FileInfo) (err error) { +func (node *Node) fill_extra(path string, fi os.FileInfo) error { stat, ok := fi.Sys().(*syscall.Stat_t) if !ok { - return + return nil } node.ChangeTime = time.Unix(stat.Ctim.Unix()) @@ -23,7 +23,7 @@ func (node *Node) fill_extra(path string, fi os.FileInfo) (err error) { node.GID = stat.Gid // TODO: cache uid lookup - if u, nil := user.LookupId(strconv.Itoa(int(stat.Uid))); err == nil { + if u, err := user.LookupId(strconv.Itoa(int(stat.Uid))); err == nil { node.User = u.Username } @@ -34,6 +34,8 @@ func (node *Node) fill_extra(path string, fi os.FileInfo) (err error) { node.Inode = stat.Ino + var err error + switch node.Type { case "file": node.Size = uint64(stat.Size)