From 7d71bad4eb626c90af16cd6d1d6bddf480eee263 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 10 Dec 2016 16:36:58 +0100 Subject: [PATCH] Test if modified files are correctly saved --- src/cmds/restic/integration_test.go | 46 +++++++++++++++++++++++++++++ src/restic/archiver/archiver.go | 2 ++ 2 files changed, 48 insertions(+) diff --git a/src/cmds/restic/integration_test.go b/src/cmds/restic/integration_test.go index 0987a47ad..d67842682 100644 --- a/src/cmds/restic/integration_test.go +++ b/src/cmds/restic/integration_test.go @@ -343,6 +343,52 @@ func TestBackupMissingFile2(t *testing.T) { }) } +func TestBackupChangedFile(t *testing.T) { + withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) { + datafile := filepath.Join("testdata", "backup-data.tar.gz") + fd, err := os.Open(datafile) + if os.IsNotExist(errors.Cause(err)) { + t.Skipf("unable to find data file %q, skipping", datafile) + return + } + OK(t, err) + OK(t, fd.Close()) + + SetupTarTestFixture(t, env.testdata, datafile) + + testRunInit(t, gopts) + + globalOptions.stderr = ioutil.Discard + defer func() { + globalOptions.stderr = os.Stderr + }() + + modFile := filepath.Join(env.testdata, "0", "0", "6", "18") + + ranHook := false + debug.Hook("archiver.SaveFile", func(context interface{}) { + pathname := context.(string) + + if pathname != modFile { + return + } + + t.Logf("in hook, modifying test file %v", modFile) + ranHook = true + + OK(t, ioutil.WriteFile(modFile, []byte("modified"), 0600)) + }) + + opts := BackupOptions{} + + testRunBackup(t, []string{env.testdata}, opts, gopts) + testRunCheck(t, gopts) + + Assert(t, ranHook, "hook did not run") + debug.RemoveHook("archiver.SaveFile") + }) +} + func TestBackupDirectoryError(t *testing.T) { withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) { datafile := filepath.Join("testdata", "backup-data.tar.gz") diff --git a/src/restic/archiver/archiver.go b/src/restic/archiver/archiver.go index 2423dc5aa..5d606176c 100644 --- a/src/restic/archiver/archiver.go +++ b/src/restic/archiver/archiver.go @@ -214,6 +214,8 @@ func (arch *Archiver) SaveFile(p *restic.Progress, node *restic.Node) error { return errors.Wrap(err, "Open") } + debug.RunHook("archiver.SaveFile", node.Path) + node, err = arch.reloadFileIfChanged(node, file) if err != nil { return err