mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-12 20:16:49 +02:00
unbound-dhcp-leases-bridge: Implement atomic file replacement
This change no longer renames the file, but removes the old link and creates a new link for the temporary file. That helps us to jump out of the code at any point without worrying about cleaning up the temporary file. Signed-off-by: Michael Tremer <michael.tremer@ipfire.org> Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
This commit is contained in:
committed by
Arne Fitzenreiter
parent
e94f3294c3
commit
c3cabfa09c
@@ -526,16 +526,22 @@ class UnboundConfigWriter(object):
|
||||
def write_dhcp_leases(self, leases):
|
||||
log.debug("Writing DHCP leases...")
|
||||
|
||||
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
|
||||
with tempfile.NamedTemporaryFile(mode="w") as f:
|
||||
for l in leases:
|
||||
for rr in l.rrset:
|
||||
f.write("local-data: \"%s\"\n" % " ".join(rr))
|
||||
|
||||
# Flush the file
|
||||
f.flush()
|
||||
|
||||
# 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.rename(f.name, self.path)
|
||||
os.link(f.name, self.path)
|
||||
|
||||
def _control(self, *args):
|
||||
command = ["unbound-control"]
|
||||
|
||||
Reference in New Issue
Block a user