From deaca157feccd50b5e5e9c84b2a9af4ce398a688 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 25 Jul 2015 12:58:55 +0200 Subject: [PATCH] restore: ignore errors Also add a test for restoring a file that is owned by root. Closes #244. --- cmd/restic/cmd_restore.go | 2 +- cmd/restic/integration_helpers_test.go | 1 + cmd/restic/integration_test.go | 27 ++++++++++++++++++ .../repo-restore-permissions-test.tar.gz | Bin 0 -> 4174 bytes 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 cmd/restic/testdata/repo-restore-permissions-test.tar.gz diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index cb74f4768..26ef9b9e0 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -76,7 +76,7 @@ func (cmd CmdRestore) Execute(args []string) error { res.Error = func(dir string, node *restic.Node, err error) error { cmd.global.Warnf("error for %s: %+v\n", dir, err) - return err + return nil } selectExcludeFilter := func(item string, dstpath string, node *restic.Node) bool { diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index fe794ab1e..6fd90ac3f 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -206,6 +206,7 @@ func configureRestic(t testing.TB, cache, repo string) GlobalOptions { password: TestPassword, stdout: os.Stdout, + stderr: os.Stderr, } } diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 999ad5a83..ed8cf3f3b 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -203,6 +203,7 @@ func TestBackupMissingFile1(t *testing.T) { cmdInit(t, global) + global.stderr = ioutil.Discard ranHook := false debug.Hook("pipe.walk1", func(context interface{}) { pathname := context.(string) @@ -240,6 +241,7 @@ func TestBackupMissingFile2(t *testing.T) { cmdInit(t, global) + global.stderr = ioutil.Discard ranHook := false debug.Hook("pipe.walk2", func(context interface{}) { pathname := context.(string) @@ -542,6 +544,31 @@ func TestRestoreFilter(t *testing.T) { }) } +func TestRestoreWithPermissionFailure(t *testing.T) { + withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) { + datafile := filepath.Join("testdata", "repo-restore-permissions-test.tar.gz") + SetupTarTestFixture(t, env.base, datafile) + + snapshots := cmdList(t, global, "snapshots") + Assert(t, len(snapshots) > 0, + "no snapshots found in repo (%v)", datafile) + + global.stderr = ioutil.Discard + cmdRestore(t, global, filepath.Join(env.base, "restore"), snapshots[0]) + + // make sure that all files have been restored, regardeless of any + // permission errors + files := cmdLs(t, global, snapshots[0].String()) + for _, filename := range files { + fi, err := os.Lstat(filepath.Join(env.base, "restore", filename)) + OK(t, err) + + Assert(t, !isFile(fi) || fi.Size() > 0, + "file %v restored, but filesize is 0", filename) + } + }) +} + func setZeroModTime(filename string) error { var utimes = []syscall.Timespec{ syscall.NsecToTimespec(0), diff --git a/cmd/restic/testdata/repo-restore-permissions-test.tar.gz b/cmd/restic/testdata/repo-restore-permissions-test.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..36aa62dbfb0ad52d5c0cafab528cfee393d388a2 GIT binary patch literal 4174 zcmV-U5V7wciwFR%ld@F+1MQi4G?i=L$Bh*w9VHDyhA7j%r#&djENpDHVWYA~^TyuT zhRBeRl9GcE5k)0aR1`U-L6nFnqRgd4=_tdyk9F31-gDM_p4NGuH|M%Q)L zt?Rz8@BRCIuitgC=)OLheBT!o7YqvZOABC-g%$zY^0D{Kw z$^COd{+IX<*FQp}<)UPlrHMe02;*V2o*!0yywY(ianw$Xy);YDw=Dg#>TO+AAH)1~ ztbEVPAmj43wLI$g<$*e`O3lFMYvr@K5W-BEw-0^e5~sH*ye)V<^39?&Sy%5Y~O#q?`W?a z75#XZosF^c<)>(?!M}QL{u5Y;e}8Y^@96=5BL4$0un_+s3gYGe#b7~yPkJ!>JN^KF z%Kza7{UHS5>Ax8KLw^7Z;~)yaz(Hgh4n;vzsB{dS29X(L90cJIGWQOOj>7^B6gNf@ zDhi?_I0Q@O-UsP)2%`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