diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-05-10 15:57:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-10 15:57:45 +0800 |
commit | e5723d6556d632df08132472066f1bb167753299 (patch) | |
tree | b7254fa85f8348af7375755bd454f59583b1bd25 /cmd | |
parent | 1e6fa57acbe3c05cb996b789e8c2d381c953826f (diff) | |
download | gitea-e5723d6556d632df08132472066f1bb167753299.tar.gz gitea-e5723d6556d632df08132472066f1bb167753299.zip |
Move restore repo to internal router and invoke from command to avoid open the same db file or queues files (#15790)
* Move restore repo to internal router and invoke from command to avoid open the same db file or queues files
* Follow @zeripath's review
* set no timeout for resotre repo private request
* make restore repo cancelable
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/restore_repo.go | 77 |
1 files changed, 11 insertions, 66 deletions
diff --git a/cmd/restore_repo.go b/cmd/restore_repo.go index 541995879b..b832471928 100644 --- a/cmd/restore_repo.go +++ b/cmd/restore_repo.go @@ -5,15 +5,12 @@ package cmd import ( - "context" - "strings" + "errors" + "net/http" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/migrations" - "code.gitea.io/gitea/modules/migrations/base" + "code.gitea.io/gitea/modules/private" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/storage" - pull_service "code.gitea.io/gitea/services/pull" "github.com/urfave/cli" ) @@ -50,70 +47,18 @@ wiki, issues, labels, releases, release_assets, milestones, pull_requests, comme } func runRestoreRepository(ctx *cli.Context) error { - if err := initDB(); err != nil { - return err - } - - log.Trace("AppPath: %s", setting.AppPath) - log.Trace("AppWorkPath: %s", setting.AppWorkPath) - log.Trace("Custom path: %s", setting.CustomPath) - log.Trace("Log path: %s", setting.LogRootPath) - setting.InitDBConfig() - - if err := storage.Init(); err != nil { - return err - } - - if err := pull_service.Init(); err != nil { - return err - } - - var opts = base.MigrateOptions{ - RepoName: ctx.String("repo_name"), - } - - if len(ctx.String("units")) == 0 { - opts.Wiki = true - opts.Issues = true - opts.Milestones = true - opts.Labels = true - opts.Releases = true - opts.Comments = true - opts.PullRequests = true - opts.ReleaseAssets = true - } else { - units := strings.Split(ctx.String("units"), ",") - for _, unit := range units { - switch strings.ToLower(unit) { - case "wiki": - opts.Wiki = true - case "issues": - opts.Issues = true - case "milestones": - opts.Milestones = true - case "labels": - opts.Labels = true - case "releases": - opts.Releases = true - case "release_assets": - opts.ReleaseAssets = true - case "comments": - opts.Comments = true - case "pull_requests": - opts.PullRequests = true - } - } - } + setting.NewContext() - if err := migrations.RestoreRepository( - context.Background(), + statusCode, errStr := private.RestoreRepo( ctx.String("repo_dir"), ctx.String("owner_name"), ctx.String("repo_name"), - ); err != nil { - log.Fatal("Failed to restore repository: %v", err) - return err + ctx.StringSlice("units"), + ) + if statusCode == http.StatusOK { + return nil } - return nil + log.Fatal("Failed to restore repository: %v", errStr) + return errors.New(errStr) } |