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)
defer file.Close()
if err != nil {
return arrar.Annotatef(err, "SaveFile(%v)", node.path)
return err
}
// check file again
@ -245,11 +245,7 @@ func (arch *Archiver) saveTree(t *Tree) (Blob, error) {
arch.fileToken <- token
}()
// TODO: handle error
err := arch.SaveFile(n)
if err != nil {
panic(err)
}
node.err = arch.SaveFile(n)
arch.p.Report(Stat{Files: 1})
}(node)
}
@ -259,9 +255,19 @@ func (arch *Archiver) saveTree(t *Tree) (Blob, error) {
// check for invalid file nodes
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)
}
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)

View file

@ -99,7 +99,7 @@ func fsckTree(opts CmdFsck, ch *restic.ContentHandler, id backend.ID) error {
switch node.Type {
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)
}

View file

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