Skip to content

Commit

Permalink
fix(cli): restore objects with I prefix fails (kopia#3062)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
NickIAm committed Mar 27, 2024
1 parent 7278f57 commit 3da0473
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions cli/command_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"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"
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/end_to_end_test/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 3da0473

Please sign in to comment.