mirror of
https://github.com/coredns/coredns.git
synced 2025-11-18 09:52:17 -05:00
Exporting Zone.File to avoid getters and setters Updating getter and setter for Zone.File to be less racy Renaming GetFile to File in zone plugin
This commit is contained in:
committed by
Miek Gieben
parent
908d4fbd23
commit
c2780f42c4
@@ -22,14 +22,15 @@ func (z *Zone) Reload() error {
|
||||
select {
|
||||
|
||||
case <-tick.C:
|
||||
reader, err := os.Open(z.file)
|
||||
zFile := z.File()
|
||||
reader, err := os.Open(zFile)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to open zone %q in %q: %v", z.origin, z.file, err)
|
||||
log.Errorf("Failed to open zone %q in %q: %v", z.origin, zFile, err)
|
||||
continue
|
||||
}
|
||||
|
||||
serial := z.SOASerialIfDefined()
|
||||
zone, err := Parse(reader, z.origin, z.file, serial)
|
||||
zone, err := Parse(reader, z.origin, zFile, serial)
|
||||
if err != nil {
|
||||
if _, ok := err.(*serialErr); !ok {
|
||||
log.Errorf("Parsing zone %q: %v", z.origin, err)
|
||||
@@ -43,7 +44,7 @@ func (z *Zone) Reload() error {
|
||||
z.Tree = zone.Tree
|
||||
z.reloadMu.Unlock()
|
||||
|
||||
log.Infof("Successfully reloaded zone %q in %q with serial %d", z.origin, z.file, z.Apex.SOA.Serial)
|
||||
log.Infof("Successfully reloaded zone %q in %q with serial %d", z.origin, zFile, z.Apex.SOA.Serial)
|
||||
z.Notify()
|
||||
|
||||
case <-z.reloadShutdown:
|
||||
|
||||
@@ -124,6 +124,20 @@ func (z *Zone) Insert(r dns.RR) error {
|
||||
// Delete deletes r from z.
|
||||
func (z *Zone) Delete(r dns.RR) { z.Tree.Delete(r) }
|
||||
|
||||
// File retrieves the file path in a safe way
|
||||
func (z *Zone) File() string {
|
||||
z.reloadMu.Lock()
|
||||
defer z.reloadMu.Unlock()
|
||||
return z.file
|
||||
}
|
||||
|
||||
// SetFile updates the file path in a safe way
|
||||
func (z *Zone) SetFile(path string) {
|
||||
z.reloadMu.Lock()
|
||||
z.file = path
|
||||
z.reloadMu.Unlock()
|
||||
}
|
||||
|
||||
// TransferAllowed checks if incoming request for transferring the zone is allowed according to the ACLs.
|
||||
func (z *Zone) TransferAllowed(state request.Request) bool {
|
||||
for _, t := range z.TransferTo {
|
||||
|
||||
Reference in New Issue
Block a user