From 909030bace0938312c8836a8c63ada491bbccff2 Mon Sep 17 00:00:00 2001 From: Matthew Grotke Date: Tue, 9 Jun 2026 10:35:38 -0400 Subject: [PATCH] Development --- routlin/mod_dnsmasq.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/routlin/mod_dnsmasq.py b/routlin/mod_dnsmasq.py index b581565..b20ec42 100644 --- a/routlin/mod_dnsmasq.py +++ b/routlin/mod_dnsmasq.py @@ -276,6 +276,8 @@ def update_blocklist_hosts(data): hosts_file = vlan_hosts_file(vlan) if not bl_names: + if hosts_file.exists(): + hosts_file.write_text("") continue if not changed.intersection(bl_names) and hosts_file.exists(): @@ -286,10 +288,10 @@ def update_blocklist_hosts(data): hosts_file.write_text(_build_merged_hosts(domains, bl_names)) _log.info(f"VLAN '{vlan_name}': wrote {len(domains):,} domains from [{', '.join(sorted(bl_names))}]") + active_vlan_names = {v["name"] for v in data.get("vlans", [])} for f in shared.DNSMASQ_CONF_DIR.glob("for-*.hosts"): vlan_name = f.stem.removeprefix("for-") - vlan = next((v for v in data.get("vlans", []) if v["name"] == vlan_name), None) - if vlan is None or not vlan.get("use_blocklists"): + if vlan_name not in active_vlan_names: f.unlink() _log.info(f"Removed stale hosts file: {f.name}")