From 4a9d49bb46be1980ff3395f9edb6f8da18934c7c Mon Sep 17 00:00:00 2001 From: Andrew Barnes <169967362+Bortlesboat@users.noreply.github.com> Date: Thu, 5 Nov 2026 18:30:31 +0000 Subject: [PATCH] fix(dump): --file extension is ignored when --type is not set (#40235) `gitea dump -f backup.tar.gz` without `--type` wrote a zip archive under that name. Detecting the type from the file name was requested in https://github.com/go-gitea/gitea/issues/24622 and intended in https://github.com/go-gitea/gitea/pull/30240, but the check read the still-empty result instead of `--file`, so every name fell back to zip. A supported extension now selects the type, other names like `backup` or `gitea.bak` still default to zip. An explicit `--type` still wins, and its help text now mentions the detection. AI disclosure: written with Claude Code (claude-opus-5-5). --------- Signed-off-by: silverwind Co-authored-by: silverwind --- cmd/dump.go | 2 +- modules/dump/dumper.go | 14 +++++--------- modules/dump/dumper_test.go | 4 +++- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cmd/dump.go b/cmd/dump.go index eddd9f7c008..aa22b0c96d9 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -90,7 +90,7 @@ func newDumpCommand() *cli.Command { }, &cli.StringFlag{ Name: "type", - Usage: `Dump output format, default to "zip", supported types: ` + strings.Join(dump.SupportedOutputTypes, ", "), + Usage: `Dump output format, default to the --file extension if supported, else "zip", supported types: ` + strings.Join(dump.SupportedOutputTypes, ", "), }, }, } diff --git a/modules/dump/dumper.go b/modules/dump/dumper.go index 7e0c22353bf..7499a7938c3 100644 --- a/modules/dump/dumper.go +++ b/modules/dump/dumper.go @@ -34,15 +34,11 @@ func PrepareFileNameAndType(argFile, argType string) (outFileName, outType strin outType = argType outFileName = fmt.Sprintf("gitea-dump-%d.%s", timeutil.TimeStampNow(), outType) } else if argType == "" { - if filepath.Ext(outFileName) == "" { - outType = SupportedOutputTypes[0] - outFileName = argFile - } else { - for _, t := range SupportedOutputTypes { - if strings.HasSuffix(argFile, "."+t) { - outFileName = argFile - outType = t - } + outFileName, outType = argFile, SupportedOutputTypes[0] + for _, t := range SupportedOutputTypes { + if strings.HasSuffix(argFile, "."+t) { + outType = t + break } } } else { diff --git a/modules/dump/dumper_test.go b/modules/dump/dumper_test.go index b713c87121b..86c5141f3e5 100644 --- a/modules/dump/dumper_test.go +++ b/modules/dump/dumper_test.go @@ -47,9 +47,11 @@ func TestPrepareFileNameAndType(t *testing.T) { test("a.zip", "tar.gz", "a.zip", "tar.gz") test("a.zip", "no-such", "", "") - test("a.tar.gz", "", "a.tar.gz", "zip") + test("a.tar.gz", "", "a.tar.gz", "tar.gz") test("a.tar.gz", "tar.gz", "a.tar.gz", "tar.gz") test("a.tar.gz", "no-such", "", "") + + test("a.b", "", "a.b", "zip") } func TestIsSubDir(t *testing.T) {