summaryrefslogtreecommitdiffstats
path: root/modules/context
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-11-13 07:01:19 +0000
committerGitHub <noreply@github.com>2019-11-13 07:01:19 +0000
commit722a7c902dd39bd3d4328345ca969220640774d7 (patch)
tree7fb83b70fd9df55fd7d3a805adf38238d6a9bca8 /modules/context
parent7b97e045557788efee6803261cf612eaf975c6be (diff)
downloadgitea-722a7c902dd39bd3d4328345ca969220640774d7.tar.gz
gitea-722a7c902dd39bd3d4328345ca969220640774d7.zip
Add Close() method to gogitRepository (#8901)
In investigating #7947 it has become clear that the storage component of go-git repositories needs closing. This PR adds this Close function and adds the Close functions as necessary. In TransferOwnership the ctx.Repo.GitRepo is closed if it is open to help prevent the risk of multiple open files. Fixes #7947
Diffstat (limited to 'modules/context')
-rw-r--r--modules/context/api.go9
-rw-r--r--modules/context/repo.go19
2 files changed, 28 insertions, 0 deletions
diff --git a/modules/context/api.go b/modules/context/api.go
index 024ae487f1..c1de37dd21 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -186,7 +186,16 @@ func ReferencesGitRepo(allowEmpty bool) macaron.Handler {
return
}
ctx.Repo.GitRepo = gitRepo
+ // We opened it, we should close it
+ defer func() {
+ // If it's been set to nil then assume someone else has closed it.
+ if ctx.Repo.GitRepo != nil {
+ ctx.Repo.GitRepo.Close()
+ }
+ }()
}
+
+ ctx.Next()
}
}
diff --git a/modules/context/repo.go b/modules/context/repo.go
index bd3456773f..f41505e7ac 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -454,9 +454,18 @@ func RepoAssignment() macaron.Handler {
}
ctx.Repo.GitRepo = gitRepo
+ // We opened it, we should close it
+ defer func() {
+ // If it's been set to nil then assume someone else has closed it.
+ if ctx.Repo.GitRepo != nil {
+ ctx.Repo.GitRepo.Close()
+ }
+ }()
+
// Stop at this point when the repo is empty.
if ctx.Repo.Repository.IsEmpty {
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
+ ctx.Next()
return
}
@@ -515,6 +524,7 @@ func RepoAssignment() macaron.Handler {
ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}"
}
+ ctx.Next()
}
}
@@ -636,6 +646,13 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
return
}
+ // We opened it, we should close it
+ defer func() {
+ // If it's been set to nil then assume someone else has closed it.
+ if ctx.Repo.GitRepo != nil {
+ ctx.Repo.GitRepo.Close()
+ }
+ }()
}
// Get default branch.
@@ -724,6 +741,8 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
return
}
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
+
+ ctx.Next()
}
}