From 33b6a7381ba2c1587e61c52c8da784e156b1cbfc Mon Sep 17 00:00:00 2001 From: Seb Patane Date: Mon, 14 Nov 2016 17:53:09 +1000 Subject: [PATCH 1/2] Don't consider a pre-existing directory in the restore path to be a failure * When a directory already exists, CreateDirAt returns an error stating so * This means that the restoreMetadata step is skipped, so for directories which already exist no file permissions, owners, groups, etc will be restored on them * Not returning the error if it's a "directory exists" error means the metadata will get restored * It also removes the superfluous "error for ...: mkdir ...: file exists" messages * This makes the behaviour of directories consistent with that of files (which always have their content & metadata restored, regardless of whether they existed or not) --- src/restic/node.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/restic/node.go b/src/restic/node.go index 81f3ef8d5..e17215125 100644 --- a/src/restic/node.go +++ b/src/restic/node.go @@ -184,7 +184,7 @@ func (node Node) RestoreTimestamps(path string) error { func (node Node) createDirAt(path string) error { err := fs.Mkdir(path, node.Mode) - if err != nil { + if err != nil && !os.IsExist(err) { return errors.Wrap(err, "Mkdir") } From 2828003d60f2e37e65d74f55f54b814ad58c615c Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Tue, 15 Nov 2016 21:41:41 +0100 Subject: [PATCH 2/2] Test that existing files and dirs are restored --- src/restic/node_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/restic/node_test.go b/src/restic/node_test.go index a2e175b14..e219d8926 100644 --- a/src/restic/node_test.go +++ b/src/restic/node_test.go @@ -137,6 +137,31 @@ var nodeTests = []restic.Node{ AccessTime: parseTime("2015-05-14 21:07:24.222"), ChangeTime: parseTime("2015-05-14 21:07:25.333"), }, + + // include "testFile" and "testDir" again with slightly different + // metadata, so we can test if CreateAt works with pre-existing files. + restic.Node{ + Name: "testFile", + Type: "file", + Content: restic.IDs{}, + UID: uint32(os.Getuid()), + GID: uint32(os.Getgid()), + Mode: 0604, + ModTime: parseTime("2005-05-14 21:07:03.111"), + AccessTime: parseTime("2005-05-14 21:07:04.222"), + ChangeTime: parseTime("2005-05-14 21:07:05.333"), + }, + restic.Node{ + Name: "testDir", + Type: "dir", + Subtree: nil, + UID: uint32(os.Getuid()), + GID: uint32(os.Getgid()), + Mode: 0750 | os.ModeDir, + ModTime: parseTime("2005-05-14 21:07:03.111"), + AccessTime: parseTime("2005-05-14 21:07:04.222"), + ChangeTime: parseTime("2005-05-14 21:07:05.333"), + }, } func TestNodeRestoreAt(t *testing.T) {