From b8620429e27ce28c565f657359b4a93b72c42837 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 7 Jan 2018 15:13:24 +0100 Subject: [PATCH] restorer: Set directory mode as last step Closes #1512 --- internal/restic/restorer.go | 26 ++++++++++++-------------- internal/restic/restorer_test.go | 13 +++++++++++++ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/internal/restic/restorer.go b/internal/restic/restorer.go index 0424fdb64..69ae7c356 100644 --- a/internal/restic/restorer.go +++ b/internal/restic/restorer.go @@ -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 } } } diff --git a/internal/restic/restorer_test.go b/internal/restic/restorer_test.go index ad3cf1423..ec3282e5d 100644 --- a/internal/restic/restorer_test.go +++ b/internal/restic/restorer_test.go @@ -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"}, },