diff options
author | 2017-06-08 18:43:11 +0100 | |
---|---|---|
committer | 2017-06-08 18:43:11 +0100 | |
commit | 990460ee7caffe752167b5307d7a5bffab37da61 (patch) | |
tree | 59dcbc4047b63eb95a1aaaa1ae2c4051bd6fee15 /middleware/file/zone.go | |
parent | 1c45e262f5cf20aaa950f8e8d86248cbce6ae120 (diff) | |
download | coredns-990460ee7caffe752167b5307d7a5bffab37da61.tar.gz coredns-990460ee7caffe752167b5307d7a5bffab37da61.tar.zst coredns-990460ee7caffe752167b5307d7a5bffab37da61.zip |
middleware/file: don't reload zone when SOA isn't changed (#707)
* middleware/file: don't reload zone when SOA isn't changed
Give Parse an extra argument which is the SOA's serial, if > 0 we check
against the just parsed SOA and then just return.
Most notable use is in reload.go which is both used in the file and auto
middleware.
Fixes #415
* PR comments
Diffstat (limited to 'middleware/file/zone.go')
-rw-r--r-- | middleware/file/zone.go | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/middleware/file/zone.go b/middleware/file/zone.go index 2d994319a..7592798f0 100644 --- a/middleware/file/zone.go +++ b/middleware/file/zone.go @@ -2,8 +2,6 @@ package file import ( "fmt" - "log" - "os" "path" "strings" "sync" @@ -12,7 +10,6 @@ import ( "github.com/coredns/coredns/middleware/proxy" "github.com/coredns/coredns/request" - "github.com/fsnotify/fsnotify" "github.com/miekg/dns" ) @@ -151,56 +148,6 @@ func (z *Zone) All() []dns.RR { return append([]dns.RR{z.Apex.SOA}, records...) } -// Reload reloads a zone when it is changed on disk. If z.NoRoload is true, no reloading will be done. -func (z *Zone) Reload() error { - if z.NoReload { - return nil - } - watcher, err := fsnotify.NewWatcher() - if err != nil { - return err - } - err = watcher.Add(path.Dir(z.file)) - if err != nil { - return err - } - - go func() { - // TODO(miek): needs to be killed on reload. - for { - select { - case event := <-watcher.Events: - if 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 - } - zone, err := Parse(reader, z.origin, z.file) - if err != nil { - log.Printf("[ERROR] Failed to parse `%s': %v", z.origin, err) - 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() - } - case <-z.ReloadShutdown: - watcher.Close() - return - } - } - }() - return nil -} - // Print prints the zone's tree to stdout. func (z *Zone) Print() { z.Tree.Print() |