Skip to content

Commit e2a83f0

Browse files
committed
local snapshot save always has .zip extension
1 parent e084b0b commit e2a83f0

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

internal/snapshot/destination.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import (
1010

1111
// ParseDestination resolves the user-supplied path to an absolute local path,
1212
// or returns an error for cloud/bare names. When dest is empty, a default name
13-
// based on now (UTC) is used, e.g. "snapshot-2026-05-11T21-04-32".
13+
// based on now (UTC) is used, e.g. "snapshot-2026-05-11T21-04-32.zip".
14+
// The returned path always has a .zip extension.
1415
func ParseDestination(dest string, now time.Time) (string, error) {
1516
if dest == "" {
1617
dest = "./" + now.UTC().Format("snapshot-2006-01-02T15-04-05")
1718
} else if strings.Contains(dest, "://") {
18-
return "", fmt.Errorf("cloud destinations are not yet supported — use a file path like ./my-snapshot")
19+
return "", fmt.Errorf("cloud destinations are not yet supported — use a file path like ./my-snapshot.zip")
1920
} else if !strings.HasPrefix(dest, ".") && !strings.HasPrefix(dest, "~") && !filepath.IsAbs(dest) && filepath.Base(dest) == dest {
2021
// bare name with no path separators: reserved for future cloud pod names
21-
return "", fmt.Errorf("cloud destinations are not yet supported — use a file path like ./my-snapshot")
22+
return "", fmt.Errorf("cloud destinations are not yet supported — use a file path like ./my-snapshot.zip")
2223
}
2324
if dest == "~" || strings.HasPrefix(dest, "~/") || strings.HasPrefix(dest, `~\`) {
2425
home, err := os.UserHomeDir()
@@ -31,5 +32,8 @@ func ParseDestination(dest string, now time.Time) (string, error) {
3132
if err != nil {
3233
return "", fmt.Errorf("resolve path: %w", err)
3334
}
35+
if !strings.EqualFold(filepath.Ext(abs), ".zip") {
36+
abs += ".zip"
37+
}
3438
return abs, nil
3539
}

internal/snapshot/destination_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestParseDestinationDefault(t *testing.T) {
2020
now := time.Date(2026, 5, 11, 21, 4, 32, 0, time.UTC)
2121
got, err := snapshot.ParseDestination("", now)
2222
require.NoError(t, err)
23-
assert.Equal(t, filepath.Join(wd, "snapshot-2026-05-11T21-04-32"), got)
23+
assert.Equal(t, filepath.Join(wd, "snapshot-2026-05-11T21-04-32.zip"), got)
2424
}
2525

2626
func TestParseDestination(t *testing.T) {
@@ -41,23 +41,31 @@ func TestParseDestination(t *testing.T) {
4141
tests := []testCase{
4242
{
4343
input: "./my-state",
44-
wantPath: filepath.Join(wd, "my-state"),
44+
wantPath: filepath.Join(wd, "my-state.zip"),
4545
},
4646
{
4747
input: filepath.Join(os.TempDir(), "state"),
48-
wantPath: filepath.Join(os.TempDir(), "state"),
48+
wantPath: filepath.Join(os.TempDir(), "state.zip"),
4949
},
5050
{
5151
input: "~",
52-
wantPath: home,
52+
wantPath: home + ".zip",
5353
},
5454
{
5555
input: "~/snapshots/s",
56-
wantPath: filepath.Join(home, "snapshots", "s"),
56+
wantPath: filepath.Join(home, "snapshots", "s.zip"),
5757
},
5858
{
5959
input: "subdir/state",
60-
wantPath: filepath.Join(wd, "subdir", "state"),
60+
wantPath: filepath.Join(wd, "subdir", "state.zip"),
61+
},
62+
{
63+
input: "./checkpoint.zip",
64+
wantPath: filepath.Join(wd, "checkpoint.zip"),
65+
},
66+
{
67+
input: "./already.ZIP",
68+
wantPath: filepath.Join(wd, "already.ZIP"),
6169
},
6270
{
6371
input: "my-pod",
@@ -75,9 +83,9 @@ func TestParseDestination(t *testing.T) {
7583

7684
if runtime.GOOS == "windows" {
7785
tests = append(tests,
78-
testCase{input: `~\snapshots\s`, wantPath: filepath.Join(home, "snapshots", "s")},
79-
testCase{input: `C:\Users\user\snap`, wantPath: `C:\Users\user\snap`},
80-
testCase{input: `C:/Users/user/snap`, wantPath: `C:\Users\user\snap`},
86+
testCase{input: `~\snapshots\s`, wantPath: filepath.Join(home, "snapshots", "s.zip")},
87+
testCase{input: `C:\Users\user\snap`, wantPath: `C:\Users\user\snap.zip`},
88+
testCase{input: `C:/Users/user/snap`, wantPath: `C:\Users\user\snap.zip`},
8189
)
8290
}
8391

@@ -88,7 +96,7 @@ func TestParseDestination(t *testing.T) {
8896
if tc.wantErr != "" {
8997
require.Error(t, err)
9098
assert.Contains(t, err.Error(), tc.wantErr)
91-
assert.Contains(t, err.Error(), "./my-snapshot")
99+
assert.Contains(t, err.Error(), "./my-snapshot.zip")
92100
return
93101
}
94102
require.NoError(t, err)

0 commit comments

Comments
 (0)