Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-02-11 20:29:11 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-02-11 20:29:11 +0300
commit920b15f69cd7749ab5f45b121132e92de2ef6e15 (patch)
tree1b7fed68042a8a537fe1c8e8a59a3cbdc9176ee6
parentf97ebb63782cb6ac681268651a2234e942b7e90a (diff)
Reduce code complexity
-rw-r--r--Makefile2
-rw-r--r--domain.go14
-rw-r--r--main.go15
3 files changed, 21 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 41fae2bd..757c0292 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ lint:
complexity:
go get github.com/fzipp/gocyclo
- gocyclo -over 9 $(wildcard *.go)
+ gocyclo -over 7 $(wildcard *.go)
test:
go get golang.org/x/tools/cmd/cover
diff --git a/domain.go b/domain.go
index 87e8a4c3..f9ddc7c1 100644
--- a/domain.go
+++ b/domain.go
@@ -40,7 +40,7 @@ func (d *domain) serveFile(w http.ResponseWriter, r *http.Request, fullPath stri
return true
}
-func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, subPath string) (fullPath string, err error) {
+func (d *domain) resolvePath(w http.ResponseWriter, r *http.Request, projectName, subPath string) (fullPath string, err error) {
publicPath := filepath.Join(*pagesRoot, d.Group, projectName, "public")
fullPath = filepath.Join(publicPath, subPath)
@@ -53,7 +53,11 @@ func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, s
err = fmt.Errorf("%q should be in %q", fullPath, publicPath)
return
}
+ return
+}
+func (d *domain) checkPath(w http.ResponseWriter, r *http.Request, path string) (fullPath string, err error) {
+ fullPath = path
fi, err := os.Lstat(fullPath)
if err != nil {
return
@@ -77,11 +81,15 @@ func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, s
}
func (d *domain) tryFile(w http.ResponseWriter, r *http.Request, projectName, subPath string) bool {
- fullPath, err := d.fullPath(w, r, projectName, subPath)
+ path, err := d.resolvePath(w, r, projectName, subPath)
+ if err != nil {
+ return false
+ }
+ path, err = d.checkPath(w, r, path)
if err != nil {
return false
}
- return d.serveFile(w, r, fullPath)
+ return d.serveFile(w, r, path)
}
func (d *domain) serveFromGroup(w http.ResponseWriter, r *http.Request) {
diff --git a/main.go b/main.go
index 586a81a4..3a6cdd9c 100644
--- a/main.go
+++ b/main.go
@@ -102,6 +102,14 @@ func (a *theApp) UpdateDomains(domains domains) {
a.lock.Unlock()
}
+func resolve() {
+ fullPath, err := filepath.EvalSymlinks(*pagesRoot)
+ if err != nil {
+ log.Fatalln(err)
+ }
+ *pagesRoot = fullPath
+}
+
func main() {
var wg sync.WaitGroup
var app theApp
@@ -109,12 +117,7 @@ func main() {
fmt.Printf("GitLab Pages Daemon %s (%s)", VERSION, REVISION)
fmt.Printf("URL: https://gitlab.com/gitlab-org/gitlab-pages")
flag.Parse()
-
- fullPath, err := filepath.EvalSymlinks(*pagesRoot)
- if err != nil {
- log.Fatalln(err)
- }
- *pagesRoot = fullPath
+ resolve()
// Listen for HTTP
if *listenHTTP != "" {