aboutsummaryrefslogtreecommitdiffstats
path: root/services/migrations/dump.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2022-06-15 20:28:03 +0800
committerGitHub <noreply@github.com>2022-06-15 20:28:03 +0800
commit9f87b60b46b2d3c6c4518d772a0fdc935d454ae0 (patch)
tree6494f3904c6b9275d3e14e14e2d1f5cdc1a5ad67 /services/migrations/dump.go
parent97548d2722201fba061d20d3119fe6ae50b834cc (diff)
downloadgitea-9f87b60b46b2d3c6c4518d772a0fdc935d454ae0.tar.gz
gitea-9f87b60b46b2d3c6c4518d772a0fdc935d454ae0.zip
Fix cli command restore-repo: "units" should be parsed as StringSlice (#19953)
* Fix cli command restore-repo: "units" should be parsed as StringSlice because after #15790 it's read by c.StringSlice("units"). Before, the "units" were processed by strings.Split * Add checking for invalid unit names Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'services/migrations/dump.go')
-rw-r--r--services/migrations/dump.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/services/migrations/dump.go b/services/migrations/dump.go
index 6410aa1ee0..ad04756d4b 100644
--- a/services/migrations/dump.go
+++ b/services/migrations/dump.go
@@ -6,6 +6,7 @@ package migrations
import (
"context"
+ "errors"
"fmt"
"io"
"net/http"
@@ -572,7 +573,7 @@ func DumpRepository(ctx context.Context, baseDir, ownerName string, opts base.Mi
return nil
}
-func updateOptionsUnits(opts *base.MigrateOptions, units []string) {
+func updateOptionsUnits(opts *base.MigrateOptions, units []string) error {
if len(units) == 0 {
opts.Wiki = true
opts.Issues = true
@@ -585,6 +586,8 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) {
} else {
for _, unit := range units {
switch strings.ToLower(unit) {
+ case "":
+ continue
case "wiki":
opts.Wiki = true
case "issues":
@@ -601,9 +604,12 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) {
opts.Comments = true
case "pull_requests":
opts.PullRequests = true
+ default:
+ return errors.New("invalid unit: " + unit)
}
}
}
+ return nil
}
// RestoreRepository restore a repository from the disk directory
@@ -626,7 +632,9 @@ func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string,
migrateOpts := base.MigrateOptions{
GitServiceType: structs.GitServiceType(tp),
}
- updateOptionsUnits(&migrateOpts, units)
+ if err := updateOptionsUnits(&migrateOpts, units); err != nil {
+ return err
+ }
if err = migrateRepository(downloader, uploader, migrateOpts, nil); err != nil {
if err1 := uploader.Rollback(); err1 != nil {