]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:samba_dnsupdate: let update_file check for modified first
authorStefan Metzmacher <metze@samba.org>
Wed, 20 May 2026 15:59:03 +0000 (17:59 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 21 Jul 2026 09:32:37 +0000 (09:32 +0000)
We only replace the file if it's modified.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
source4/scripting/bin/samba_dnsupdate

index 8342b0ac547c3446b9d7dff8afa885c55194b201..dd9040a79bcfedaee2224c3e026ab1bd0dca3b66 100755 (executable)
@@ -428,17 +428,29 @@ def update_file(write_file, d, op):
     (file_dir, file_name) = os.path.split(write_file)
     (tmp_fd, tmpfile) = tempfile.mkstemp(dir=file_dir, prefix=file_name, suffix="XXXXXX")
     wfile = os.fdopen(tmp_fd, 'a')
+    modified = False
     for line in rfile:
+        l = parse_dns_line(line, {})
+        if str(l).lower() != str(d).lower():
+            wfile.write(line)
+            continue
         if op == "delete":
-            l = parse_dns_line(line, {})
-            if str(l).lower() == str(d).lower():
-                continue
-        wfile.write(line)
+            modified = True
+            continue
+        if op == "add":
+            op = "skip_add"
+            wfile.write(line)
+            continue
+        continue
     if op == "add":
         wfile.write(str(d)+"\n")
+        modified = True
     rfile.close()
     wfile.close()
-    os.rename(tmpfile, write_file)
+    if modified:
+        os.rename(tmpfile, write_file)
+    else:
+        os.remove(tmpfile)
     return
 
 def call_nsupdate(d, op="add"):