From 3bcf2e5c180996fd136cf08c12ade0cc0796e71e Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 15 May 2021 23:45:17 +0200 Subject: [PATCH] Close the gitrepo when deleting the repository (#15876) (#15887) Signed-off-by: Andrew Thornton Co-authored-by: zeripath --- modules/migrations/gitea_uploader.go | 1 + routers/admin/repos.go | 4 ++++ routers/api/v1/repo/repo.go | 4 ++++ routers/repo/setting.go | 5 +++++ 4 files changed, 14 insertions(+) diff --git a/modules/migrations/gitea_uploader.go b/modules/migrations/gitea_uploader.go index 02f97c4ff..868a0ea5e 100644 --- a/modules/migrations/gitea_uploader.go +++ b/modules/migrations/gitea_uploader.go @@ -849,6 +849,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error { // Rollback when migrating failed, this will rollback all the changes. func (g *GiteaLocalUploader) Rollback() error { if g.repo != nil && g.repo.ID > 0 { + g.gitRepo.Close() if err := models.DeleteRepository(g.doer, g.repo.OwnerID, g.repo.ID); err != nil { return err } diff --git a/routers/admin/repos.go b/routers/admin/repos.go index 46d0b60f2..44a682d99 100644 --- a/routers/admin/repos.go +++ b/routers/admin/repos.go @@ -46,6 +46,10 @@ func DeleteRepo(ctx *context.Context) { return } + if ctx.Repo != nil && ctx.Repo.GitRepo != nil && ctx.Repo.Repository != nil && ctx.Repo.Repository.ID == repo.ID { + ctx.Repo.GitRepo.Close() + } + if err := repo_service.DeleteRepository(ctx.User, repo); err != nil { ctx.ServerError("DeleteRepository", err) return diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 4d96516d2..cc6221ff9 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -885,6 +885,10 @@ func Delete(ctx *context.APIContext) { return } + if ctx.Repo.GitRepo != nil { + ctx.Repo.GitRepo.Close() + } + if err := repo_service.DeleteRepository(ctx.User, repo); err != nil { ctx.Error(http.StatusInternalServerError, "DeleteRepository", err) return diff --git a/routers/repo/setting.go b/routers/repo/setting.go index dc14b69b3..effa7483c 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -539,6 +539,11 @@ func SettingsPost(ctx *context.Context) { return } + // Close the gitrepository before doing this. + if ctx.Repo.GitRepo != nil { + ctx.Repo.GitRepo.Close() + } + if err := repo_service.DeleteRepository(ctx.User, ctx.Repo.Repository); err != nil { ctx.ServerError("DeleteRepository", err) return