summaryrefslogtreecommitdiffstats
path: root/routers/repo/wiki.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 /routers/repo/wiki.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 'routers/repo/wiki.go')
-rw-r--r--routers/repo/wiki.go70
1 files changed, 69 insertions, 1 deletions
diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go
index 02fbe4a1dd..6cf1943658 100644
--- a/routers/repo/wiki.go
+++ b/routers/repo/wiki.go
@@ -146,6 +146,9 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
// Get page list.
entries, err := commit.ListEntries()
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
ctx.ServerError("ListEntries", err)
return nil, nil
}
@@ -159,6 +162,9 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
if models.IsErrWikiInvalidFileName(err) {
continue
}
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
ctx.ServerError("WikiFilenameToName", err)
return nil, nil
} else if wikiName == "_Sidebar" || wikiName == "_Footer" {
@@ -188,16 +194,25 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
}
if entry == nil || ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return nil, nil
}
sidebarContent, _, _, _ := wikiContentsByName(ctx, commit, "_Sidebar")
if ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return nil, nil
}
footerContent, _, _, _ := wikiContentsByName(ctx, commit, "_Footer")
if ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return nil, nil
}
@@ -218,6 +233,9 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
wikiRepo, commit, err := findWikiRepoCommit(ctx)
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
if !git.IsErrNotExist(err) {
ctx.ServerError("GetBranchCommit", err)
}
@@ -241,6 +259,9 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
}
if entry == nil || ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return nil, nil
}
@@ -263,6 +284,9 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
// get Commit Count
commitsHistory, err := wikiRepo.CommitsByFileAndRangeNoFollow("master", pageFilename, page)
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
ctx.ServerError("CommitsByFileAndRangeNoFollow", err)
return nil, nil
}
@@ -279,13 +303,21 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
}
func renderEditPage(ctx *context.Context) {
- _, commit, err := findWikiRepoCommit(ctx)
+ wikiRepo, commit, err := findWikiRepoCommit(ctx)
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
if !git.IsErrNotExist(err) {
ctx.ServerError("GetBranchCommit", err)
}
return
}
+ defer func() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ }()
// get requested pagename
pageName := models.NormalizeWikiName(ctx.Params(":page"))
@@ -327,8 +359,16 @@ func Wiki(ctx *context.Context) {
wikiRepo, entry := renderViewPage(ctx)
if ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return
}
+ defer func() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ }()
if entry == nil {
ctx.Data["Title"] = ctx.Tr("repo.wiki")
ctx.HTML(200, tplWikiStart)
@@ -364,8 +404,16 @@ func WikiRevision(ctx *context.Context) {
wikiRepo, entry := renderRevisionPage(ctx)
if ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return
}
+ defer func() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ }()
if entry == nil {
ctx.Data["Title"] = ctx.Tr("repo.wiki")
ctx.HTML(200, tplWikiStart)
@@ -397,11 +445,18 @@ func WikiPages(ctx *context.Context) {
wikiRepo, commit, err := findWikiRepoCommit(ctx)
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return
}
entries, err := commit.ListEntries()
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+
ctx.ServerError("ListEntries", err)
return
}
@@ -412,6 +467,10 @@ func WikiPages(ctx *context.Context) {
}
c, err := wikiRepo.GetCommitByPath(entry.Name())
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+
ctx.ServerError("GetCommit", err)
return
}
@@ -420,6 +479,10 @@ func WikiPages(ctx *context.Context) {
if models.IsErrWikiInvalidFileName(err) {
continue
}
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+
ctx.ServerError("WikiFilenameToName", err)
return
}
@@ -431,6 +494,11 @@ func WikiPages(ctx *context.Context) {
}
ctx.Data["Pages"] = pages
+ defer func() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ }()
ctx.HTML(200, tplWikiPages)
}