mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
Use filepath when manipulating file paths (#2221)
Automatically submitted.
This commit is contained in:
committed by
corbot[bot]
parent
cf04223718
commit
4b1b0ec9e6
@@ -2,7 +2,7 @@ package auto
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -104,8 +104,8 @@ func autoParse(c *caddy.Controller) (Auto, error) {
|
||||
return a, c.ArgErr()
|
||||
}
|
||||
a.loader.directory = c.Val()
|
||||
if !path.IsAbs(a.loader.directory) && config.Root != "" {
|
||||
a.loader.directory = path.Join(config.Root, a.loader.directory)
|
||||
if !filepath.IsAbs(a.loader.directory) && config.Root != "" {
|
||||
a.loader.directory = filepath.Join(config.Root, a.loader.directory)
|
||||
}
|
||||
_, err := os.Stat(a.loader.directory)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,7 +2,6 @@ package auto
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
@@ -91,7 +90,7 @@ func (a Auto) Walk() error {
|
||||
// matches matches re to filename, if is is a match, the subexpression will be used to expand
|
||||
// template to an origin. When match is true that origin is returned. Origin is fully qualified.
|
||||
func matches(re *regexp.Regexp, filename, template string) (match bool, origin string) {
|
||||
base := path.Base(filename)
|
||||
base := filepath.Base(filename)
|
||||
|
||||
matches := re.FindStringSubmatchIndex(base)
|
||||
if matches == nil {
|
||||
|
||||
@@ -3,7 +3,7 @@ package auto
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
@@ -73,15 +73,15 @@ func createFiles() (string, error) {
|
||||
}
|
||||
|
||||
for _, name := range dbFiles {
|
||||
if err := ioutil.WriteFile(path.Join(dir, name), []byte(zoneContent), 0644); err != nil {
|
||||
if err := ioutil.WriteFile(filepath.Join(dir, name), []byte(zoneContent), 0644); err != nil {
|
||||
return dir, err
|
||||
}
|
||||
}
|
||||
// symlinks
|
||||
if err = os.Symlink(path.Join(dir, "db.example.org"), path.Join(dir, "db.example.com")); err != nil {
|
||||
if err = os.Symlink(filepath.Join(dir, "db.example.org"), filepath.Join(dir, "db.example.com")); err != nil {
|
||||
return dir, err
|
||||
}
|
||||
if err = os.Symlink(path.Join(dir, "db.example.org"), path.Join(dir, "aa.example.com")); err != nil {
|
||||
if err = os.Symlink(filepath.Join(dir, "db.example.org"), filepath.Join(dir, "aa.example.com")); err != nil {
|
||||
return dir, err
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package auto
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
@@ -39,7 +39,7 @@ func TestWatcher(t *testing.T) {
|
||||
}
|
||||
|
||||
// Now remove one file, rescan and see if it's gone.
|
||||
if err := os.Remove(path.Join(tempdir, "db.example.com")); err != nil {
|
||||
if err := os.Remove(filepath.Join(tempdir, "db.example.com")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -78,15 +78,15 @@ func TestSymlinks(t *testing.T) {
|
||||
a.Walk()
|
||||
|
||||
// Now create a duplicate file in a subdirectory and repoint the symlink
|
||||
if err := os.Remove(path.Join(tempdir, "db.example.com")); err != nil {
|
||||
if err := os.Remove(filepath.Join(tempdir, "db.example.com")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dataDir := path.Join(tempdir, "..data")
|
||||
dataDir := filepath.Join(tempdir, "..data")
|
||||
if err = os.Mkdir(dataDir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newFile := path.Join(dataDir, "db.example.com")
|
||||
if err = os.Symlink(path.Join(tempdir, "db.example.org"), newFile); err != nil {
|
||||
newFile := filepath.Join(dataDir, "db.example.com")
|
||||
if err = os.Symlink(filepath.Join(tempdir, "db.example.org"), newFile); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user