mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Close the gitrepo when deleting the repository (#15876)
Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
		@@ -851,6 +851,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
 | 
				
			|||||||
// Rollback when migrating failed, this will rollback all the changes.
 | 
					// Rollback when migrating failed, this will rollback all the changes.
 | 
				
			||||||
func (g *GiteaLocalUploader) Rollback() error {
 | 
					func (g *GiteaLocalUploader) Rollback() error {
 | 
				
			||||||
	if g.repo != nil && g.repo.ID > 0 {
 | 
						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 {
 | 
							if err := models.DeleteRepository(g.doer, g.repo.OwnerID, g.repo.ID); err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,6 +47,10 @@ func DeleteRepo(ctx *context.Context) {
 | 
				
			|||||||
		return
 | 
							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 {
 | 
						if err := repo_service.DeleteRepository(ctx.User, repo); err != nil {
 | 
				
			||||||
		ctx.ServerError("DeleteRepository", err)
 | 
							ctx.ServerError("DeleteRepository", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -889,6 +889,10 @@ func Delete(ctx *context.APIContext) {
 | 
				
			|||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if ctx.Repo.GitRepo != nil {
 | 
				
			||||||
 | 
							ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := repo_service.DeleteRepository(ctx.User, repo); err != nil {
 | 
						if err := repo_service.DeleteRepository(ctx.User, repo); err != nil {
 | 
				
			||||||
		ctx.Error(http.StatusInternalServerError, "DeleteRepository", err)
 | 
							ctx.Error(http.StatusInternalServerError, "DeleteRepository", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -544,6 +544,11 @@ func SettingsPost(ctx *context.Context) {
 | 
				
			|||||||
			return
 | 
								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 {
 | 
							if err := repo_service.DeleteRepository(ctx.User, ctx.Repo.Repository); err != nil {
 | 
				
			||||||
			ctx.ServerError("DeleteRepository", err)
 | 
								ctx.ServerError("DeleteRepository", err)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user