]> source.dussan.org Git - gitea.git/commitdiff
RepoAssignment ensure to close before overwrite (#19449) (#19460)
author6543 <6543@obermui.de>
Thu, 21 Apr 2022 16:55:44 +0000 (18:55 +0200)
committerGitHub <noreply@github.com>
Thu, 21 Apr 2022 16:55:44 +0000 (18:55 +0200)
* check if GitRepo already open and close if

* Only run RepoAssignment once

modules/context/repo.go

index ac00c2c10d9fd3e9fedd19eb68c591d7a9007423..4eeab710ff67a6f8c720f924b18a5cfade3f1ec4 100644 (file)
@@ -410,6 +410,12 @@ func RepoIDAssignment() func(ctx *Context) {
 
 // RepoAssignment returns a middleware to handle repository assignment
 func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
+       if _, repoAssignmentOnce := ctx.Data["repoAssignmentExecuted"]; repoAssignmentOnce {
+               log.Trace("RepoAssignment was exec already, skipping second call ...")
+               return
+       }
+       ctx.Data["repoAssignmentExecuted"] = true
+
        var (
                owner *user_model.User
                err   error
@@ -592,6 +598,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
                ctx.ServerError("RepoAssignment Invalid repo "+repo_model.RepoPath(userName, repoName), err)
                return
        }
+       if ctx.Repo.GitRepo != nil {
+               ctx.Repo.GitRepo.Close()
+       }
        ctx.Repo.GitRepo = gitRepo
 
        // We opened it, we should close it