aboutsummaryrefslogtreecommitdiff
path: root/middleware/file/zone.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-10-27 21:01:04 +0100
committerGravatar GitHub <noreply@github.com> 2016-10-27 21:01:04 +0100
commit039596f319c40622293f883317c9d35d7bb79e0c (patch)
treedae2a8083dc75c7ebaef93f6f4ceed44b24fc4af /middleware/file/zone.go
parent94dc28646d0852541b378a627631de8c83785de8 (diff)
downloadcoredns-039596f319c40622293f883317c9d35d7bb79e0c.tar.gz
coredns-039596f319c40622293f883317c9d35d7bb79e0c.tar.zst
coredns-039596f319c40622293f883317c9d35d7bb79e0c.zip
middleware/file: add test for reload (#361)
This add a highlevel integration test for zone reloading. It also fixes a data race in the actual reloading process.
Diffstat (limited to 'middleware/file/zone.go')
-rw-r--r--middleware/file/zone.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/middleware/file/zone.go b/middleware/file/zone.go
index b503aa5d2..b71822d4e 100644
--- a/middleware/file/zone.go
+++ b/middleware/file/zone.go
@@ -163,22 +163,24 @@ func (z *Zone) Reload() error {
select {
case event := <-watcher.Events:
if event.Op == fsnotify.Write && path.Clean(event.Name) == z.file {
+
reader, err := os.Open(z.file)
if err != nil {
log.Printf("[ERROR] Failed to open `%s' for `%s': %v", z.file, z.origin, err)
continue
}
- z.reloadMu.Lock()
zone, err := Parse(reader, z.origin, z.file)
if err != nil {
log.Printf("[ERROR] Failed to parse `%s': %v", z.origin, err)
- z.reloadMu.Unlock()
continue
}
+
// copy elements we need
+ z.reloadMu.Lock()
z.Apex = zone.Apex
z.Tree = zone.Tree
z.reloadMu.Unlock()
+
log.Printf("[INFO] Successfully reloaded zone `%s'", z.origin)
z.Notify()
}