Update modified files, store error message

This commit is contained in:
Alexander Neumann 2015-01-04 22:58:58 +01:00
parent e543f5926c
commit 6eb969a492
3 changed files with 17 additions and 8 deletions

View File

@ -98,7 +98,7 @@ func (arch *Archiver) SaveFile(node *Node) error {
file, err := os.Open(node.path) file, err := os.Open(node.path)
defer file.Close() defer file.Close()
if err != nil { if err != nil {
return arrar.Annotatef(err, "SaveFile(%v)", node.path) return err
} }
// check file again // check file again
@ -245,11 +245,7 @@ func (arch *Archiver) saveTree(t *Tree) (Blob, error) {
arch.fileToken <- token arch.fileToken <- token
}() }()
// TODO: handle error node.err = arch.SaveFile(n)
err := arch.SaveFile(n)
if err != nil {
panic(err)
}
arch.p.Report(Stat{Files: 1}) arch.p.Report(Stat{Files: 1})
}(node) }(node)
} }
@ -259,9 +255,19 @@ func (arch *Archiver) saveTree(t *Tree) (Blob, error) {
// check for invalid file nodes // check for invalid file nodes
for _, node := range *t { for _, node := range *t {
if node.Type == "file" && node.Content == nil { if node.Type == "file" && node.Content == nil && node.err == nil {
return Blob{}, fmt.Errorf("node %v has empty content", node.Name) return Blob{}, fmt.Errorf("node %v has empty content", node.Name)
} }
if node.err != nil {
err := arch.Error(node.path, nil, node.err)
if err != nil {
return Blob{}, err
}
// save error message in node
node.Error = node.err.Error()
}
} }
blob, err := arch.SaveJSON(backend.Tree, t) blob, err := arch.SaveJSON(backend.Tree, t)

View File

@ -99,7 +99,7 @@ func fsckTree(opts CmdFsck, ch *restic.ContentHandler, id backend.ID) error {
switch node.Type { switch node.Type {
case "file": case "file":
if node.Content == nil { if node.Content == nil && node.Error == "" {
return fmt.Errorf("file node %q of tree %v has no content", node.Name, id) return fmt.Errorf("file node %q of tree %v has no content", node.Name, id)
} }

View File

@ -39,6 +39,8 @@ type Node struct {
Content []backend.ID `json:"content"` Content []backend.ID `json:"content"`
Subtree backend.ID `json:"subtree,omitempty"` Subtree backend.ID `json:"subtree,omitempty"`
Error string `json:"error,omitempty"`
tree *Tree tree *Tree
path string path string
@ -96,6 +98,7 @@ func LoadTree(ch *ContentHandler, id backend.ID) (Tree, error) {
// LoadTreeRecursive loads the tree and all subtrees via ch. // LoadTreeRecursive loads the tree and all subtrees via ch.
func LoadTreeRecursive(path string, ch *ContentHandler, id backend.ID) (Tree, error) { func LoadTreeRecursive(path string, ch *ContentHandler, id backend.ID) (Tree, error) {
// TODO: load subtrees in parallel
tree, err := LoadTree(ch, id) tree, err := LoadTree(ch, id)
if err != nil { if err != nil {
return nil, err return nil, err