restorer: Set directory mode as last step

Closes #1512
This commit is contained in:
Alexander Neumann 2018-01-07 15:13:24 +01:00
parent aab414b368
commit b8620429e2
2 changed files with 25 additions and 14 deletions

View File

@ -79,13 +79,6 @@ func (res *Restorer) restoreTo(ctx context.Context, target, location string, tre
selectedForRestore, childMayBeSelected := res.SelectFilter(nodeLocation, nodeTarget, node) selectedForRestore, childMayBeSelected := res.SelectFilter(nodeLocation, nodeTarget, node)
debug.Log("SelectFilter returned %v %v", selectedForRestore, childMayBeSelected) debug.Log("SelectFilter returned %v %v", selectedForRestore, childMayBeSelected)
if selectedForRestore {
err = res.restoreNodeTo(ctx, node, nodeTarget, nodeLocation, idx)
if err != nil {
return err
}
}
if node.Type == "dir" && childMayBeSelected { if node.Type == "dir" && childMayBeSelected {
if node.Subtree == nil { if node.Subtree == nil {
return errors.Errorf("Dir without subtree in tree %v", treeID.Str()) return errors.Errorf("Dir without subtree in tree %v", treeID.Str())
@ -98,8 +91,14 @@ func (res *Restorer) restoreTo(ctx context.Context, target, location string, tre
return err return err
} }
} }
}
if selectedForRestore { if selectedForRestore {
err = res.restoreNodeTo(ctx, node, nodeTarget, nodeLocation, idx)
if err != nil {
return err
}
// Restore directory timestamp at the end. If we would do it earlier, restoring files within // Restore directory timestamp at the end. If we would do it earlier, restoring files within
// the directory would overwrite the timestamp of the directory they are in. // the directory would overwrite the timestamp of the directory they are in.
err = node.RestoreTimestamps(nodeTarget) err = node.RestoreTimestamps(nodeTarget)
@ -108,7 +107,6 @@ func (res *Restorer) restoreTo(ctx context.Context, target, location string, tre
} }
} }
} }
}
return nil return nil
} }

View File

@ -178,6 +178,19 @@ func TestRestorer(t *testing.T) {
Nodes: map[string]Node{ Nodes: map[string]Node{
"dir": Dir{ "dir": Dir{
Mode: 0444, Mode: 0444,
},
"file": File{"top-level file"},
},
},
Files: map[string]string{
"file": "top-level file",
},
},
{
Snapshot: Snapshot{
Nodes: map[string]Node{
"dir": Dir{
Mode: 0555,
Nodes: map[string]Node{ Nodes: map[string]Node{
"file": File{"file in dir"}, "file": File{"file in dir"},
}, },