From 3da0473219bf466a8d0a4b7eb5a3b0e634ea1766 Mon Sep 17 00:00:00 2001 From: NickIAm Date: Wed, 27 Mar 2024 14:03:46 +1000 Subject: [PATCH] fix(cli): restore objects with I prefix fails (#3062) * Fix restoring objects with I prefix set default of snapshot-time to 'latest' as noted in the help output * Change test of restore to check it works without a time given This is because --snapshot-time defaults to "latest" now. --- cli/command_restore.go | 5 ++--- tests/end_to_end_test/restore_test.go | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cli/command_restore.go b/cli/command_restore.go index 2d1909290..eb7b2df28 100644 --- a/cli/command_restore.go +++ b/cli/command_restore.go @@ -21,7 +21,6 @@ "github.com/kopia/kopia/internal/timetrack" "github.com/kopia/kopia/internal/units" "github.com/kopia/kopia/repo" - "github.com/kopia/kopia/repo/content/index" "github.com/kopia/kopia/repo/object" "github.com/kopia/kopia/snapshot" "github.com/kopia/kopia/snapshot/restore" @@ -147,7 +146,7 @@ func (c *commandRestore) setup(svc appServices, parent commandParent) { cmd.Flag("skip-existing", "Skip files and symlinks that exist in the output").BoolVar(&c.restoreIncremental) cmd.Flag("shallow", "Shallow restore the directory hierarchy starting at this level (default is to deep restore the entire hierarchy.)").Int32Var(&c.restoreShallowAtDepth) cmd.Flag("shallow-minsize", "When doing a shallow restore, write actual files instead of placeholders smaller than this size.").Int32Var(&c.minSizeForPlaceholder) - cmd.Flag("snapshot-time", "When using a path as the source, use the latest snapshot available before this date. Default is latest").StringVar(&c.snapshotTime) + cmd.Flag("snapshot-time", "When using a path as the source, use the latest snapshot available before this date. Default is latest").Default("latest").StringVar(&c.snapshotTime) cmd.Action(svc.repositoryReaderAction(c.run)) } @@ -452,7 +451,7 @@ func (c *commandRestore) tryToConvertPathToID(ctx context.Context, rep repo.Repo pathElements := strings.Split(filepath.ToSlash(source), "/") if pathElements[0] != "" { - _, err := index.ParseID(pathElements[0]) + _, err := object.ParseID(pathElements[0]) if err == nil { // source is an ID return source, nil diff --git a/tests/end_to_end_test/restore_test.go b/tests/end_to_end_test/restore_test.go index 995c008f5..14b258e4d 100644 --- a/tests/end_to_end_test/restore_test.go +++ b/tests/end_to_end_test/restore_test.go @@ -864,6 +864,6 @@ func TestRestoreByPathWithoutTarget(t *testing.T) { require.NoError(t, err) require.Equal(t, originalData, data) - // Must pass snapshot time - e.RunAndExpectFailure(t, "restore", srcdir) + // Defaults to latest snapshot time + e.RunAndExpectSuccess(t, "restore", srcdir) }