From: Daniel Salzman Date: Fri, 21 Dec 2018 15:19:56 +0000 (+0100) Subject: sql import: update zone file atomically X-Git-Tag: v2.8.0~98^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec5cf9f3c1923b25036e79e855676e53a3e6c05d;p=thirdparty%2Fknot-dns.git sql import: update zone file atomically --- diff --git a/scripts/dns_sql2zf.py b/scripts/dns_sql2zf.py index 60d6034d8d..9fb7dd9e28 100755 --- a/scripts/dns_sql2zf.py +++ b/scripts/dns_sql2zf.py @@ -168,10 +168,13 @@ def print_domain(domain, change_type = 0, txn = None): global slave_mode dn = domain_id2name(domain, txn) if str(domain).isdigit() else domain if not slave_mode: - f = open(zone_storage(dn), "w") + file_name = zone_storage(dn) + tmp_name = "%s.tmp" % file_name + f = open(tmp_name, "w") for r in domain_get_records(domain, txn): print_record(r, f) f.close() + os.rename(tmp_name, file_name) if knotc_socket is not None: knotc_send(change_type, dn) print("Updated zone %s" % dn)