summaryrefslogtreecommitdiffstats
path: root/modules/base
diff options
context:
space:
mode:
authorRichard Mahn <richmahn@users.noreply.github.com>2019-04-17 10:06:35 -0600
committertechknowlogick <matti@mdranta.net>2019-04-17 12:06:35 -0400
commit2262811e407facea09047e94aa1850c192511587 (patch)
treea478624613dc6cf095784d629f9627b197de15e8 /modules/base
parent059195b127848d96a4690257af19d8c97c6d2363 (diff)
downloadgitea-2262811e407facea09047e94aa1850c192511587.tar.gz
gitea-2262811e407facea09047e94aa1850c192511587.zip
Fixes 4762 - Content API for Creating, Updating, Deleting Files (#6314)
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/tool.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 681577b76f..97fd87e85c 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -16,7 +16,10 @@ import (
"math"
"net/http"
"net/url"
+ "os"
"path"
+ "path/filepath"
+ "runtime"
"strconv"
"strings"
"time"
@@ -603,3 +606,25 @@ func EntryIcon(entry *git.TreeEntry) string {
return "file-text"
}
+
+// SetupGiteaRoot Sets GITEA_ROOT if it is not already set and returns the value
+func SetupGiteaRoot() string {
+ giteaRoot := os.Getenv("GITEA_ROOT")
+ if giteaRoot == "" {
+ _, filename, _, _ := runtime.Caller(0)
+ giteaRoot = strings.TrimSuffix(filename, "modules/base/tool.go")
+ wd, err := os.Getwd()
+ if err != nil {
+ rel, err := filepath.Rel(giteaRoot, wd)
+ if err != nil && strings.HasPrefix(filepath.ToSlash(rel), "../") {
+ giteaRoot = wd
+ }
+ }
+ if _, err := os.Stat(filepath.Join(giteaRoot, "gitea")); os.IsNotExist(err) {
+ giteaRoot = ""
+ } else if err := os.Setenv("GITEA_ROOT", giteaRoot); err != nil {
+ giteaRoot = ""
+ }
+ }
+ return giteaRoot
+}