From 973fa921cb6bb19de6233532e1100bf779908d28 Mon Sep 17 00:00:00 2001 From: greatroar <@> Date: Thu, 20 Feb 2020 11:56:33 +0100 Subject: [PATCH] Test and document Restorer.VerifyFiles --- internal/restorer/restorer.go | 5 ++++- internal/restorer/restorer_test.go | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/restorer/restorer.go b/internal/restorer/restorer.go index 75ed99f86..b87a8a6f7 100644 --- a/internal/restorer/restorer.go +++ b/internal/restorer/restorer.go @@ -310,7 +310,10 @@ func (res *Restorer) Snapshot() *restic.Snapshot { return res.sn } -// VerifyFiles reads all snapshot files and verifies their contents +// VerifyFiles checks whether all regular files in the snapshot res.sn +// have been successfully written to dst. It stops when it encounters an +// error. It returns that error and the number of files it has checked, +// including the file(s) that caused errors. func (res *Restorer) VerifyFiles(ctx context.Context, dst string) (int, error) { // TODO multithreaded? diff --git a/internal/restorer/restorer_test.go b/internal/restorer/restorer_test.go index 32be0f51d..4a51c2c19 100644 --- a/internal/restorer/restorer_test.go +++ b/internal/restorer/restorer_test.go @@ -367,6 +367,11 @@ func TestRestorer(t *testing.T) { t.Fatal(err) } + if len(test.ErrorsMust)+len(test.ErrorsMay) == 0 { + _, err = res.VerifyFiles(ctx, tempdir) + rtest.OK(t, err) + } + for location, expectedErrors := range test.ErrorsMust { actualErrors, ok := errors[location] if !ok { @@ -465,6 +470,9 @@ func TestRestorerRelative(t *testing.T) { if err != nil { t.Fatal(err) } + nverified, err := res.VerifyFiles(ctx, "restore") + rtest.OK(t, err) + rtest.Equals(t, len(test.Files), nverified) for filename, err := range errors { t.Errorf("unexpected error for %v found: %v", filename, err)