1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-25 09:18:55 +00:00

restore: ignore errors

Also add a test for restoring a file that is owned by root. Closes #244.
This commit is contained in:
Alexander Neumann 2015-07-25 12:58:55 +02:00
parent b5ebd702fe
commit deaca157fe
4 changed files with 29 additions and 1 deletions

View file

@ -76,7 +76,7 @@ func (cmd CmdRestore) Execute(args []string) error {
res.Error = func(dir string, node *restic.Node, err error) error { res.Error = func(dir string, node *restic.Node, err error) error {
cmd.global.Warnf("error for %s: %+v\n", dir, err) cmd.global.Warnf("error for %s: %+v\n", dir, err)
return err return nil
} }
selectExcludeFilter := func(item string, dstpath string, node *restic.Node) bool { selectExcludeFilter := func(item string, dstpath string, node *restic.Node) bool {

View file

@ -206,6 +206,7 @@ func configureRestic(t testing.TB, cache, repo string) GlobalOptions {
password: TestPassword, password: TestPassword,
stdout: os.Stdout, stdout: os.Stdout,
stderr: os.Stderr,
} }
} }

View file

@ -203,6 +203,7 @@ func TestBackupMissingFile1(t *testing.T) {
cmdInit(t, global) cmdInit(t, global)
global.stderr = ioutil.Discard
ranHook := false ranHook := false
debug.Hook("pipe.walk1", func(context interface{}) { debug.Hook("pipe.walk1", func(context interface{}) {
pathname := context.(string) pathname := context.(string)
@ -240,6 +241,7 @@ func TestBackupMissingFile2(t *testing.T) {
cmdInit(t, global) cmdInit(t, global)
global.stderr = ioutil.Discard
ranHook := false ranHook := false
debug.Hook("pipe.walk2", func(context interface{}) { debug.Hook("pipe.walk2", func(context interface{}) {
pathname := context.(string) 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 { func setZeroModTime(filename string) error {
var utimes = []syscall.Timespec{ var utimes = []syscall.Timespec{
syscall.NsecToTimespec(0), syscall.NsecToTimespec(0),

Binary file not shown.