Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
4b1b0ec9
Commit
4b1b0ec9
authored
Oct 21, 2018
by
Manuel Stocker
Committed by
corbot[bot]
Oct 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use filepath when manipulating file paths (#2221)
Automatically submitted.
parent
cf042237
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
32 additions
and
33 deletions
+32
-33
plugin/auto/setup.go
plugin/auto/setup.go
+3
-3
plugin/auto/walk.go
plugin/auto/walk.go
+1
-2
plugin/auto/walk_test.go
plugin/auto/walk_test.go
+4
-4
plugin/auto/watcher_test.go
plugin/auto/watcher_test.go
+6
-6
plugin/dnssec/setup.go
plugin/dnssec/setup.go
+3
-3
plugin/file/setup.go
plugin/file/setup.go
+3
-3
plugin/file/zone.go
plugin/file/zone.go
+2
-2
plugin/hosts/setup.go
plugin/hosts/setup.go
+3
-3
test/auto_test.go
test/auto_test.go
+4
-4
test/metrics_test.go
test/metrics_test.go
+3
-3
No files found.
plugin/auto/setup.go
View file @
4b1b0ec9
...
@@ -2,7 +2,7 @@ package auto
...
@@ -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) {
...
@@ -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
!
file
path
.
IsAbs
(
a
.
loader
.
directory
)
&&
config
.
Root
!=
""
{
a
.
loader
.
directory
=
path
.
Join
(
config
.
Root
,
a
.
loader
.
directory
)
a
.
loader
.
directory
=
file
path
.
Join
(
config
.
Root
,
a
.
loader
.
directory
)
}
}
_
,
err
:=
os
.
Stat
(
a
.
loader
.
directory
)
_
,
err
:=
os
.
Stat
(
a
.
loader
.
directory
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
plugin/auto/walk.go
View file @
4b1b0ec9
...
@@ -2,7 +2,6 @@ package auto
...
@@ -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 {
...
@@ -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
:=
file
path
.
Base
(
filename
)
matches
:=
re
.
FindStringSubmatchIndex
(
base
)
matches
:=
re
.
FindStringSubmatchIndex
(
base
)
if
matches
==
nil
{
if
matches
==
nil
{
...
...
plugin/auto/walk_test.go
View file @
4b1b0ec9
...
@@ -3,7 +3,7 @@ package auto
...
@@ -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) {
...
@@ -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
(
file
path
.
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"
),
file
path
.
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"
),
file
path
.
Join
(
dir
,
"aa.example.com"
));
err
!=
nil
{
return
dir
,
err
return
dir
,
err
}
}
...
...
plugin/auto/watcher_test.go
View file @
4b1b0ec9
...
@@ -2,7 +2,7 @@ package auto
...
@@ -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) {
...
@@ -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
(
file
path
.
Join
(
tempdir
,
"db.example.com"
));
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -78,15 +78,15 @@ func TestSymlinks(t *testing.T) {
...
@@ -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
(
file
path
.
Join
(
tempdir
,
"db.example.com"
));
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
dataDir
:=
path
.
Join
(
tempdir
,
"..data"
)
dataDir
:=
file
path
.
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
:=
file
path
.
Join
(
dataDir
,
"db.example.com"
)
if
err
=
os
.
Symlink
(
path
.
Join
(
tempdir
,
"db.example.org"
),
newFile
);
err
!=
nil
{
if
err
=
os
.
Symlink
(
file
path
.
Join
(
tempdir
,
"db.example.org"
),
newFile
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
...
plugin/dnssec/setup.go
View file @
4b1b0ec9
...
@@ -2,7 +2,7 @@ package dnssec
...
@@ -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) {
...
@@ -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
!
file
path
.
IsAbs
(
base
)
&&
config
.
Root
!=
""
{
base
=
path
.
Join
(
config
.
Root
,
base
)
base
=
file
path
.
Join
(
config
.
Root
,
base
)
}
}
k
,
err
:=
ParseKeyFile
(
base
+
".key"
,
base
+
".private"
)
k
,
err
:=
ParseKeyFile
(
base
+
".key"
,
base
+
".private"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
plugin/file/setup.go
View file @
4b1b0ec9
...
@@ -2,7 +2,7 @@ package file
...
@@ -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) {
...
@@ -71,8 +71,8 @@ func fileParse(c *caddy.Controller) (Zones, error) {
origins
=
args
origins
=
args
}
}
if
!
path
.
IsAbs
(
fileName
)
&&
config
.
Root
!=
""
{
if
!
file
path
.
IsAbs
(
fileName
)
&&
config
.
Root
!=
""
{
fileName
=
path
.
Join
(
config
.
Root
,
fileName
)
fileName
=
file
path
.
Join
(
config
.
Root
,
fileName
)
}
}
reader
,
err
:=
os
.
Open
(
fileName
)
reader
,
err
:=
os
.
Open
(
fileName
)
...
...
plugin/file/zone.go
View file @
4b1b0ec9
...
@@ -3,7 +3,7 @@ package file
...
@@ -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 {
...
@@ -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
:
file
path
.
Clean
(
file
),
Tree
:
&
tree
.
Tree
{},
Tree
:
&
tree
.
Tree
{},
Expired
:
new
(
bool
),
Expired
:
new
(
bool
),
reloadShutdown
:
make
(
chan
bool
),
reloadShutdown
:
make
(
chan
bool
),
...
...
plugin/hosts/setup.go
View file @
4b1b0ec9
...
@@ -2,7 +2,7 @@ package hosts
...
@@ -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) {
...
@@ -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
!
file
path
.
IsAbs
(
h
.
path
)
&&
config
.
Root
!=
""
{
h
.
path
=
path
.
Join
(
config
.
Root
,
h
.
path
)
h
.
path
=
file
path
.
Join
(
config
.
Root
,
h
.
path
)
}
}
s
,
err
:=
os
.
Stat
(
h
.
path
)
s
,
err
:=
os
.
Stat
(
h
.
path
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
test/auto_test.go
View file @
4b1b0ec9
...
@@ -3,7 +3,7 @@ package test
...
@@ -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) {
...
@@ -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
(
file
path
.
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) {
...
@@ -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
(
file
path
.
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) {
...
@@ -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
(
file
path
.
Join
(
tmpdir
,
"db.example.org"
),
[]
byte
(
zoneContent
),
0644
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
...
test/metrics_test.go
View file @
4b1b0ec9
...
@@ -3,7 +3,7 @@ package test
...
@@ -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) {
...
@@ -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
(
file
path
.
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) {
...
@@ -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
(
file
path
.
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment