diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2018-03-08 19:13:11 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2018-03-08 19:13:11 +0300 |
commit | 0a94a639adf87d0e2ad20eeefc2aaaef6f376701 (patch) | |
tree | 1f76484eb960976f19d925de5865494f425b5ed5 | |
parent | 1b45fd2c9a9d0e4bc39516c257115c6186d103b2 (diff) |
Don't allow custom root dir
-rw-r--r-- | domain_config.go | 2 | ||||
-rw-r--r-- | domains.go | 8 | ||||
-rw-r--r-- | domains_test.go | 18 |
3 files changed, 12 insertions, 16 deletions
diff --git a/domain_config.go b/domain_config.go index 85a7b636..f5c3db79 100644 --- a/domain_config.go +++ b/domain_config.go @@ -31,7 +31,7 @@ func (c *domainConfig) Valid(rootDomain string) bool { } func (c *domainsConfig) Read(group, project string) (err error) { - configFile, err := os.Open(filepath.Join(rootDir, group, project, "config.json")) + configFile, err := os.Open(filepath.Join(group, project, "config.json")) if err != nil { return err } @@ -78,7 +78,7 @@ func (d domains) readProject(rootDomain, group, projectName string) { return } - if _, err := os.Lstat(filepath.Join(rootDir, group, projectName, "public")); err != nil { + if _, err := os.Lstat(filepath.Join(group, projectName, "public")); err != nil { return } @@ -86,7 +86,7 @@ func (d domains) readProject(rootDomain, group, projectName string) { } func (d domains) readProjects(rootDomain, group string, buf []byte) { - fis, err := godirwalk.ReadDirents(filepath.Join(rootDir, group), buf) + fis, err := godirwalk.ReadDirents(group, buf) if err != nil { log.WithError(err).WithFields(log.Fields{ "group": group, @@ -104,12 +104,10 @@ func (d domains) readProjects(rootDomain, group string, buf []byte) { } } -var rootDir = "." - func (d domains) ReadGroups(rootDomain string) error { buf := make([]byte, 2*os.Getpagesize()) - fis, err := godirwalk.ReadDirents(rootDir, buf) + fis, err := godirwalk.ReadDirents(".", buf) if err != nil { return err } diff --git a/domains_test.go b/domains_test.go index 36321edb..af1594e1 100644 --- a/domains_test.go +++ b/domains_test.go @@ -5,7 +5,6 @@ import ( "fmt" "io/ioutil" "os" - "path/filepath" "testing" "time" @@ -91,18 +90,17 @@ func TestWatchDomains(t *testing.T) { func BenchmarkReadGroups(b *testing.B) { testRoot, err := ioutil.TempDir("", "gitlab-pages-test") require.NoError(b, err) - testRoot, err = filepath.EvalSymlinks(testRoot) + + cwd, err := os.Getwd() require.NoError(b, err) - defer func(dir string) { - fmt.Printf("cleaning up test directory %s\n", dir) - os.RemoveAll(dir) - }(testRoot) + defer func(oldWd, testWd string) { + os.Chdir(oldWd) + fmt.Printf("cleaning up test directory %s\n", testWd) + os.RemoveAll(testWd) + }(cwd, testRoot) - defer func(d string) { - rootDir = d - }(rootDir) - rootDir = testRoot + require.NoError(b, os.Chdir(testRoot)) nGroups := 10000 b.Logf("creating fake domains directory with %d groups", nGroups) |