Skip to content

Commit

Permalink
Close the gitrepo when deleting the repository (#15876)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath authored May 14, 2021
1 parent f6be429 commit d0ea10b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/migrations/gitea_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,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
}
Expand Down
4 changes: 4 additions & 0 deletions routers/admin/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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
Expand Down
4 changes: 4 additions & 0 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,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
Expand Down
5 changes: 5 additions & 0 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,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
Expand Down

0 comments on commit d0ea10b

Please sign in to comment.