unbound-dhcp-leases-bridge: Make comparison work if old file does not exist

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>
This commit is contained in:
Michael Tremer
2024-04-26 15:09:19 +00:00
committed by Arne Fitzenreiter
parent 749bf85902
commit 4bf50efa84

View 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)