Save peer settings file using write-then-copy

This commit is contained in:
Mark Qvist
2025-12-22 11:27:05 +01:00
parent a2e6a06a35
commit 5253cccfa7

View File

@@ -245,6 +245,7 @@ class NomadNetworkApp:
self.peer_settings["served_file_requests"] = 0
except Exception as e:
RNS.logdest = RNS.LOG_STDOUT
RNS.log(f"Could not load local peer settings from {self.peersettingspath}", RNS.LOG_ERROR)
RNS.log(f"The contained exception was: {e}", RNS.LOG_ERROR)
RNS.log(f"This likely means that the peer settings file has become corrupt.", RNS.LOG_ERROR)
@@ -560,9 +561,9 @@ class NomadNetworkApp:
return self.message_router.get_outbound_propagation_node()
def save_peer_settings(self):
file = open(self.peersettingspath, "wb")
file.write(msgpack.packb(self.peer_settings))
file.close()
tmp_path = f"{self.peersettingspath}.tmp"
with open(tmp_path, "wb") as file: file.write(msgpack.packb(self.peer_settings))
os.replace(tmp_path, self.peersettingspath)
def lxmf_delivery(self, message):
time_string = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(message.timestamp))