Use filepath when manipulating file paths (#2221)
Automatically submitted.
This commit is contained in:
parent
cf04223718
commit
4b1b0ec9e6
10 changed files with 32 additions and 33 deletions
|
@ -2,7 +2,7 @@ package auto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
@ -104,8 +104,8 @@ func autoParse(c *caddy.Controller) (Auto, error) {
|
||||||
return a, c.ArgErr()
|
return a, c.ArgErr()
|
||||||
}
|
}
|
||||||
a.loader.directory = c.Val()
|
a.loader.directory = c.Val()
|
||||||
if !path.IsAbs(a.loader.directory) && config.Root != "" {
|
if !filepath.IsAbs(a.loader.directory) && config.Root != "" {
|
||||||
a.loader.directory = path.Join(config.Root, a.loader.directory)
|
a.loader.directory = filepath.Join(config.Root, a.loader.directory)
|
||||||
}
|
}
|
||||||
_, err := os.Stat(a.loader.directory)
|
_, err := os.Stat(a.loader.directory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package auto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"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
|
// 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.
|
// 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) {
|
func matches(re *regexp.Regexp, filename, template string) (match bool, origin string) {
|
||||||
base := path.Base(filename)
|
base := filepath.Base(filename)
|
||||||
|
|
||||||
matches := re.FindStringSubmatchIndex(base)
|
matches := re.FindStringSubmatchIndex(base)
|
||||||
if matches == nil {
|
if matches == nil {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package auto
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -73,15 +73,15 @@ func createFiles() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, name := range dbFiles {
|
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
|
return dir, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// symlinks
|
// 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
|
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
|
return dir, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package auto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -39,7 +39,7 @@ func TestWatcher(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now remove one file, rescan and see if it's gone.
|
// 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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,15 +78,15 @@ func TestSymlinks(t *testing.T) {
|
||||||
a.Walk()
|
a.Walk()
|
||||||
|
|
||||||
// Now create a duplicate file in a subdirectory and repoint the symlink
|
// 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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
dataDir := path.Join(tempdir, "..data")
|
dataDir := filepath.Join(tempdir, "..data")
|
||||||
if err = os.Mkdir(dataDir, 0755); err != nil {
|
if err = os.Mkdir(dataDir, 0755); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
newFile := path.Join(dataDir, "db.example.com")
|
newFile := filepath.Join(dataDir, "db.example.com")
|
||||||
if err = os.Symlink(path.Join(tempdir, "db.example.org"), newFile); err != nil {
|
if err = os.Symlink(filepath.Join(tempdir, "db.example.org"), newFile); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package dnssec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -146,8 +146,8 @@ func keyParse(c *caddy.Controller) ([]*DNSKEY, error) {
|
||||||
if strings.HasSuffix(k, ".private") {
|
if strings.HasSuffix(k, ".private") {
|
||||||
base = k[:len(k)-8]
|
base = k[:len(k)-8]
|
||||||
}
|
}
|
||||||
if !path.IsAbs(base) && config.Root != "" {
|
if !filepath.IsAbs(base) && config.Root != "" {
|
||||||
base = path.Join(config.Root, base)
|
base = filepath.Join(config.Root, base)
|
||||||
}
|
}
|
||||||
k, err := ParseKeyFile(base+".key", base+".private")
|
k, err := ParseKeyFile(base+".key", base+".private")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
|
@ -71,8 +71,8 @@ func fileParse(c *caddy.Controller) (Zones, error) {
|
||||||
origins = args
|
origins = args
|
||||||
}
|
}
|
||||||
|
|
||||||
if !path.IsAbs(fileName) && config.Root != "" {
|
if !filepath.IsAbs(fileName) && config.Root != "" {
|
||||||
fileName = path.Join(config.Root, fileName)
|
fileName = filepath.Join(config.Root, fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
reader, err := os.Open(fileName)
|
reader, err := os.Open(fileName)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package file
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"path"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -48,7 +48,7 @@ func NewZone(name, file string) *Zone {
|
||||||
z := &Zone{
|
z := &Zone{
|
||||||
origin: dns.Fqdn(name),
|
origin: dns.Fqdn(name),
|
||||||
origLen: dns.CountLabel(dns.Fqdn(name)),
|
origLen: dns.CountLabel(dns.Fqdn(name)),
|
||||||
file: path.Clean(file),
|
file: filepath.Clean(file),
|
||||||
Tree: &tree.Tree{},
|
Tree: &tree.Tree{},
|
||||||
Expired: new(bool),
|
Expired: new(bool),
|
||||||
reloadShutdown: make(chan bool),
|
reloadShutdown: make(chan bool),
|
||||||
|
|
|
@ -2,7 +2,7 @@ package hosts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -83,8 +83,8 @@ func hostsParse(c *caddy.Controller) (Hosts, error) {
|
||||||
h.path = args[0]
|
h.path = args[0]
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
|
|
||||||
if !path.IsAbs(h.path) && config.Root != "" {
|
if !filepath.IsAbs(h.path) && config.Root != "" {
|
||||||
h.path = path.Join(config.Root, h.path)
|
h.path = filepath.Join(config.Root, h.path)
|
||||||
}
|
}
|
||||||
s, err := os.Stat(h.path)
|
s, err := os.Stat(h.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package test
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ func TestAuto(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write db.example.org to get example.org.
|
// Write db.example.org to get example.org.
|
||||||
if err = ioutil.WriteFile(path.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
if err = ioutil.WriteFile(filepath.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ func TestAuto(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove db.example.org again.
|
// Remove db.example.org again.
|
||||||
os.Remove(path.Join(tmpdir, "db.example.org"))
|
os.Remove(filepath.Join(tmpdir, "db.example.org"))
|
||||||
|
|
||||||
time.Sleep(1100 * time.Millisecond) // wait for it to be picked up
|
time.Sleep(1100 * time.Millisecond) // wait for it to be picked up
|
||||||
resp, err = p.Lookup(state, "www.example.org.", dns.TypeA)
|
resp, err = p.Lookup(state, "www.example.org.", dns.TypeA)
|
||||||
|
@ -139,7 +139,7 @@ func TestAutoAXFR(t *testing.T) {
|
||||||
defer i.Stop()
|
defer i.Stop()
|
||||||
|
|
||||||
// Write db.example.org to get example.org.
|
// Write db.example.org to get example.org.
|
||||||
if err = ioutil.WriteFile(path.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
if err = ioutil.WriteFile(filepath.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package test
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ func TestMetricsAuto(t *testing.T) {
|
||||||
defer i.Stop()
|
defer i.Stop()
|
||||||
|
|
||||||
// Write db.example.org to get example.org.
|
// Write db.example.org to get example.org.
|
||||||
if err = ioutil.WriteFile(path.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
if err = ioutil.WriteFile(filepath.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// TODO(miek): make the auto sleep even less.
|
// TODO(miek): make the auto sleep even less.
|
||||||
|
@ -169,7 +169,7 @@ func TestMetricsAuto(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove db.example.org again. And see if the metric stops increasing.
|
// Remove db.example.org again. And see if the metric stops increasing.
|
||||||
os.Remove(path.Join(tmpdir, "db.example.org"))
|
os.Remove(filepath.Join(tmpdir, "db.example.org"))
|
||||||
time.Sleep(1100 * time.Millisecond) // wait for it to be picked up
|
time.Sleep(1100 * time.Millisecond) // wait for it to be picked up
|
||||||
if _, err := dns.Exchange(m, udp); err != nil {
|
if _, err := dns.Exchange(m, udp); err != nil {
|
||||||
t.Fatalf("Could not send message: %s", err)
|
t.Fatalf("Could not send message: %s", err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue