From: 6543 <6543@obermui.de> Date: Thu, 21 Apr 2022 16:55:44 +0000 (+0200) Subject: RepoAssignment ensure to close before overwrite (#19449) (#19460) X-Git-Tag: v1.16.7~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=297346a7628c726a02fa14cbf1ba3edec5122ecd;p=gitea.git RepoAssignment ensure to close before overwrite (#19449) (#19460) * check if GitRepo already open and close if * Only run RepoAssignment once --- diff --git a/modules/context/repo.go b/modules/context/repo.go index ac00c2c10d..4eeab710ff 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -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