mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 04:45:15 +00:00
Update modified files, store error message
This commit is contained in:
parent
e543f5926c
commit
6eb969a492
20
archiver.go
20
archiver.go
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
3
tree.go
3
tree.go
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user