aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/repo.go
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/git/repo.go
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/git/repo.go')
-rw-r--r--modules/git/repo.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/git/repo.go b/modules/git/repo.go
index 80f6109772..ffca2524be 100644
--- a/modules/git/repo.go
+++ b/modules/git/repo.go
@@ -17,6 +17,7 @@ import (
"strings"
"time"
+ gitealog "code.gitea.io/gitea/modules/log"
"github.com/unknwon/com"
"gopkg.in/src-d/go-billy.v4/osfs"
gogit "gopkg.in/src-d/go-git.v4"
@@ -122,6 +123,16 @@ func OpenRepository(repoPath string) (*Repository, error) {
}, nil
}
+// Close this repository, in particular close the underlying gogitStorage if this is not nil
+func (repo *Repository) Close() {
+ if repo == nil || repo.gogitStorage == nil {
+ return
+ }
+ if err := repo.gogitStorage.Close(); err != nil {
+ gitealog.Error("Error closing storage: %v", err)
+ }
+}
+
// GoGitRepo gets the go-git repo representation
func (repo *Repository) GoGitRepo() *gogit.Repository {
return repo.gogitRepo