Browse Source

Close the gitrepo when deleting the repository (#15876) (#15887)

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: zeripath <art27@cantab.net>
mj-v1.14.3
6543 1 year ago
committed by GitHub
parent
commit
3bcf2e5c18
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      modules/migrations/gitea_uploader.go
  2. 4
      routers/admin/repos.go
  3. 4
      routers/api/v1/repo/repo.go
  4. 5
      routers/repo/setting.go

1
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
}

4
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

4
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

5
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

Loading…
Cancel
Save