]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
unbound-dhcp-leases-bridge: Make comparison work if old file does not exist
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 26 Apr 2024 15:09:19 +0000 (15:09 +0000)
committerArne Fitzenreiter <arne_f@ipfire.org>
Sun, 28 Apr 2024 17:23:41 +0000 (17:23 +0000)
This patch catches any errors if the file did not previously exist and
therefore skips the comparison.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
config/unbound/unbound-dhcp-leases-bridge

index 80c8267e80b361aa257ce915bdc5cc3d8995fa91..7f89f620a1400c5542e2d9585ffa4b658d2a115e 100644 (file)
@@ -535,17 +535,22 @@ class UnboundConfigWriter(object):
                        f.flush()
 
                        # Compare if the new leases file has changed from the previous version
-                       if filecmp.cmp(f.name, self.path, shallow=False):
-                               log.debug("The generated leases file has not changed")
+                       try:
+                               if filecmp.cmp(f.name, self.path, shallow=False):
+                                       log.debug("The generated leases file has not changed")
 
-                               return False
+                                       return False
+
+                               # Remove the old file
+                               os.unlink(self.path)
+
+                       # If the previous file did not exist, just keep falling through
+                       except FileNotFoundError:
+                               pass
 
                        # Make file readable for everyone
                        os.fchmod(f.fileno(), stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IROTH)
 
-                       # Remove the old file
-                       os.unlink(self.path)
-
                        # Move the file to its destination
                        os.link(f.name, self.path)