mirror of
https://github.com/coredns/coredns.git
synced 2026-07-10 09:40:12 -04:00
fix(auto): keep first matching zone file for duplicate origins (#8216)
Signed-off-by: immanuwell <pchpr.00@list.ru>
This commit is contained in:
committed by
GitHub
parent
1e01c0ad7c
commit
5cab9853cd
@@ -44,12 +44,14 @@ func (a Auto) Walk() error {
|
|||||||
cleanPath := filepath.Clean(path)
|
cleanPath := filepath.Clean(path)
|
||||||
if previous, ok := seen[origin]; ok && previous != cleanPath {
|
if previous, ok := seen[origin]; ok && previous != cleanPath {
|
||||||
log.Warningf("Multiple zone files match origin %q: using %q instead of %q", origin, path, previous)
|
log.Warningf("Multiple zone files match origin %q: using %q instead of %q", origin, path, previous)
|
||||||
|
toDelete[origin] = false
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
seen[origin] = cleanPath
|
seen[origin] = cleanPath
|
||||||
|
|
||||||
if z, ok := a.Z[origin]; ok {
|
if z, ok := a.Z[origin]; ok {
|
||||||
toDelete[origin] = false
|
toDelete[origin] = false
|
||||||
z.SetFile(path)
|
z.SetFile(cleanPath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,37 @@ func TestWalkWarnsForDuplicateOrigin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWalkKeepsFirstMatchingFileForOrigin(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
zone := filepath.Join(dir, "example.org.zone")
|
||||||
|
backup := filepath.Join(dir, "example.org.zone.bak-20260528")
|
||||||
|
|
||||||
|
for _, path := range []string{zone, backup} {
|
||||||
|
if err := os.WriteFile(path, []byte(zoneContent), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
a := Auto{
|
||||||
|
loader: loader{
|
||||||
|
directory: dir,
|
||||||
|
re: regexp.MustCompile(`(.*)\.zone`),
|
||||||
|
template: `${1}`,
|
||||||
|
},
|
||||||
|
Zones: &Zones{},
|
||||||
|
}
|
||||||
|
|
||||||
|
a.Walk()
|
||||||
|
if got := a.Z["example.org."].File(); got != zone {
|
||||||
|
t.Fatalf("zone file = %q, want %q", got, zone)
|
||||||
|
}
|
||||||
|
|
||||||
|
a.Walk()
|
||||||
|
if got := a.Z["example.org."].File(); got != zone {
|
||||||
|
t.Fatalf("zone file after reload = %q, want %q", got, zone)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func createFiles(t *testing.T) (string, error) {
|
func createFiles(t *testing.T) (string, error) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|||||||
Reference in New Issue
Block a user