mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-09 17:37:20 -06:00
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 <me@silverwind.io> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -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, ", "),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user