Skip to content

Ensure wiki repos are all closed (#16886) #16890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 26 additions & 32 deletions routers/repo/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package repo
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"path/filepath"
"strings"
Expand Down Expand Up @@ -131,6 +132,9 @@ func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName strin
func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
wikiRepo, commit, err := findUncycloRepoCommit(ctx)
if err != nil {
if wikiRepo != nil {
wikiRepo.Close()
}
if !git.IsErrNotExist(err) {
ctx.ServerError("GetBranchCommit", err)
}
Expand Down Expand Up @@ -354,17 +358,14 @@ func Uncyclo(ctx *context.Context) {
}

wikiRepo, entry := renderViewPage(ctx)
if ctx.Written() {
if wikiRepo != nil {
wikiRepo.Close()
}
return
}
defer func() {
if wikiRepo != nil {
wikiRepo.Close()
}
}()
if ctx.Written() {
return
}
if entry == nil {
ctx.Data["Title"] = ctx.Tr("repo.wiki")
ctx.HTML(200, tplUncycloStart)
Expand Down Expand Up @@ -399,17 +400,15 @@ func UncycloRevision(ctx *context.Context) {
}

wikiRepo, entry := renderRevisionPage(ctx)
if ctx.Written() {
if wikiRepo != nil {
wikiRepo.Close()
}
return
}
defer func() {
if wikiRepo != nil {
wikiRepo.Close()
}
}()

if ctx.Written() {
return
}
if entry == nil {
ctx.Data["Title"] = ctx.Tr("repo.wiki")
ctx.HTML(200, tplUncycloStart)
Expand Down Expand Up @@ -446,13 +445,14 @@ func UncycloPages(ctx *context.Context) {
}
return
}

entries, err := commit.ListEntries()
if err != nil {
defer func() {
if wikiRepo != nil {
wikiRepo.Close()
}
}()

entries, err := commit.ListEntries()
if err != nil {
ctx.ServerError("ListEntries", err)
return
}
Expand All @@ -463,10 +463,6 @@ func UncycloPages(ctx *context.Context) {
}
c, err := wikiRepo.GetCommitByPath(entry.Name())
if err != nil {
if wikiRepo != nil {
wikiRepo.Close()
}

ctx.ServerError("GetCommit", err)
return
}
Expand All @@ -475,10 +471,6 @@ func UncycloPages(ctx *context.Context) {
if models.IsErrUncycloInvalidFileName(err) {
continue
}
if wikiRepo != nil {
wikiRepo.Close()
}

ctx.ServerError("UncycloFilenameToName", err)
return
}
Expand All @@ -490,21 +482,25 @@ func UncycloPages(ctx *context.Context) {
}
ctx.Data["Pages"] = pages

ctx.HTML(http.StatusOK, tplUncycloPages)
}

// UncycloRaw outputs raw blob requested by user (image for example)
func UncycloRaw(ctx *context.Context) {
wikiRepo, commit, err := findUncycloRepoCommit(ctx)
defer func() {
if wikiRepo != nil {
wikiRepo.Close()
}
}()
ctx.HTML(200, tplUncycloPages)
}

// UncycloRaw outputs raw blob requested by user (image for example)
func UncycloRaw(ctx *context.Context) {
wikiRepo, commit, err := findUncycloRepoCommit(ctx)
if err != nil {
if wikiRepo != nil {
if git.IsErrNotExist(err) {
ctx.NotFound("findEntryForFile", nil)
return
}
ctx.ServerError("findEntryForfile", err)
return
}

providedPath := ctx.Params("*")
Expand All @@ -520,9 +516,7 @@ func UncycloRaw(ctx *context.Context) {

if entry == nil {
// Try to find a wiki page with that name
if strings.HasSuffix(providedPath, ".md") {
providedPath = providedPath[:len(providedPath)-3]
}
providedPath = strings.TrimSuffix(providedPath, ".md")

wikiPath := wiki_service.NameToFilename(providedPath)
entry, err = findEntryForFile(commit, wikiPath)
Expand Down