mirror of
https://github.com/coredns/coredns.git
synced 2026-10-16 23:35:43 -04:00
plugin/file: track zone mtime for reload_by_mtime (#8556)
* plugin/file: track zone mtime for reload_by_mtime Signed-off-by: git-jxj <65210887+git-jxj@users.noreply.github.com> * plugin/file: capture initial mtime before parsing Signed-off-by: git-jxj <65210887+git-jxj@users.noreply.github.com> * plugin/file: keep unloaded zones retryable after open error Signed-off-by: git-jxj <65210887+git-jxj@users.noreply.github.com> --------- Signed-off-by: git-jxj <65210887+git-jxj@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package file
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@@ -69,6 +70,10 @@ func setup(c *caddy.Controller) error {
|
||||
}
|
||||
|
||||
func fileParse(c *caddy.Controller) (Zones, fall.F, error) {
|
||||
return fileParseWithParser(c, Parse)
|
||||
}
|
||||
|
||||
func fileParseWithParser(c *caddy.Controller, parse func(io.Reader, string, string, int64) (*Zone, error)) (Zones, fall.F, error) {
|
||||
z := make(map[string]*Zone)
|
||||
names := []string{}
|
||||
fall := fall.F{}
|
||||
@@ -95,6 +100,12 @@ func fileParse(c *caddy.Controller) (Zones, fall.F, error) {
|
||||
if err != nil {
|
||||
openErr = err
|
||||
}
|
||||
var openedFileInfo os.FileInfo
|
||||
if err == nil {
|
||||
// Capture the version represented by the opened reader, before
|
||||
// parsing can race with a replacement at the same pathname.
|
||||
openedFileInfo, _ = reader.Stat()
|
||||
}
|
||||
|
||||
err = func() error {
|
||||
defer reader.Close()
|
||||
@@ -103,7 +114,7 @@ func fileParse(c *caddy.Controller) (Zones, fall.F, error) {
|
||||
z[origins[i]] = NewZone(origins[i], fileName)
|
||||
if openErr == nil {
|
||||
reader.Seek(0, 0)
|
||||
zone, err := Parse(reader, origins[i], fileName, 0)
|
||||
zone, err := parse(reader, origins[i], fileName, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -147,6 +158,9 @@ func fileParse(c *caddy.Controller) (Zones, fall.F, error) {
|
||||
z[origins[i]].ReloadInterval = reload
|
||||
z[origins[i]].Upstream = upstream.New()
|
||||
z[origins[i]].ReloadByMtime = reload_by_mtime
|
||||
if reload_by_mtime && openErr == nil && openedFileInfo != nil {
|
||||
z[origins[i]].file_mtime = openedFileInfo.ModTime()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user