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)
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.Subtree == nil {
return errors.Errorf("Dir without subtree in tree %v", treeID.Str())
@ -98,14 +91,19 @@ func (res *Restorer) restoreTo(ctx context.Context, target, location string, tre
return err
}
}
}
if selectedForRestore {
// 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.
err = node.RestoreTimestamps(nodeTarget)
if err != nil {
return err
}
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
// the directory would overwrite the timestamp of the directory they are in.
err = node.RestoreTimestamps(nodeTarget)
if err != nil {
return err
}
}
}

View File

@ -178,6 +178,19 @@ func TestRestorer(t *testing.T) {
Nodes: map[string]Node{
"dir": Dir{
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{
"file": File{"file in dir"},
},