diff options
author | 2016-10-28 12:57:02 +0100 | |
---|---|---|
committer | 2016-10-28 12:57:02 +0100 | |
commit | 0509f4b4aca9f0e516e641921763e3dd5edead4f (patch) | |
tree | 003836a622ae7fe53596e11e0c3b94c1c3f03aed /middleware/file/zone.go | |
parent | 54964653d10aa8b2e34ac21e007c701ceb456f7d (diff) | |
download | coredns-0509f4b4aca9f0e516e641921763e3dd5edead4f.tar.gz coredns-0509f4b4aca9f0e516e641921763e3dd5edead4f.tar.zst coredns-0509f4b4aca9f0e516e641921763e3dd5edead4f.zip |
middleware/file: reload on file mv (#365)
When a file is moved into position we should also reload the zones'
content.
This also fixes deadlock bug in the locking, a reload would block any
further lookups.
Diffstat (limited to 'middleware/file/zone.go')
-rw-r--r-- | middleware/file/zone.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/middleware/file/zone.go b/middleware/file/zone.go index b71822d4e..ddedc6725 100644 --- a/middleware/file/zone.go +++ b/middleware/file/zone.go @@ -123,8 +123,10 @@ func (z *Zone) TransferAllowed(req request.Request) bool { // All returns all records from the zone, the first record will be the SOA record, // otionally followed by all RRSIG(SOA)s. func (z *Zone) All() []dns.RR { - z.reloadMu.RLock() - defer z.reloadMu.RUnlock() + if !z.NoReload { + z.reloadMu.RLock() + defer z.reloadMu.RUnlock() + } records := []dns.RR{} allNodes := z.Tree.All() @@ -162,7 +164,9 @@ func (z *Zone) Reload() error { for { select { case event := <-watcher.Events: - if event.Op == fsnotify.Write && path.Clean(event.Name) == z.file { + // Looks for Write and Create events. Write is obvious, Create is used when + // a file in mv-ed into this place. + if (event.Op == fsnotify.Write || event.Op == fsnotify.Create) && path.Clean(event.Name) == z.file { reader, err := os.Open(z.file) if err != nil { |