fix(auto): keep first matching zone file for duplicate origins (#8216)

Signed-off-by: immanuwell <pchpr.00@list.ru>
This commit is contained in:
Immanuel Tikhonov
2026-07-10 04:43:07 +04:00
committed by GitHub
parent 1e01c0ad7c
commit 5cab9853cd
2 changed files with 34 additions and 1 deletions

View File

@@ -44,12 +44,14 @@ func (a Auto) Walk() error {
cleanPath := filepath.Clean(path)
if previous, ok := seen[origin]; ok && previous != cleanPath {
log.Warningf("Multiple zone files match origin %q: using %q instead of %q", origin, path, previous)
toDelete[origin] = false
return nil
}
seen[origin] = cleanPath
if z, ok := a.Z[origin]; ok {
toDelete[origin] = false
z.SetFile(path)
z.SetFile(cleanPath)
return nil
}

View File

@@ -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) {
t.Helper()
dir := t.TempDir()