From 5243d646f0778621a598e466c79abf6d6b367b16 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 18 May 2026 14:57:17 +0200 Subject: [PATCH] Improved known destination persist reliability --- RNS/Identity.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/RNS/Identity.py b/RNS/Identity.py index e2d1b6bb..78b7a7ed 100644 --- a/RNS/Identity.py +++ b/RNS/Identity.py @@ -212,8 +212,17 @@ class Identity: RNS.log("Skipped recombining known destinations from disk, since an error occurred: "+str(e), RNS.LOG_WARNING) RNS.log("Saving "+str(len(Identity.known_destinations))+" known destinations to storage...", RNS.LOG_VERBOSE) - with open(RNS.Reticulum.storagepath+"/known_destinations","wb") as file: - umsgpack.dump(Identity.known_destinations.copy(), file) + temp_file = RNS.Reticulum.storagepath+f"/known_destinations.tmp.{time.time()}" + + try: + with open(temp_file,"wb") as file: umsgpack.dump(Identity.known_destinations.copy(), file) + os.rename(temp_file, RNS.Reticulum.storagepath+f"/known_destinations") + + except Exception as e: + RNS.log(f"Error while serializing and writing known destinations: {e}", RNS.LOG_ERROR) + try: os.unlink(temp_file) + except Exception as e: RNS.log(f"Could not clean up temporary file {temp_file}: {e}", RNS.LOG_WARNING) + raise e save_time = time.time() - save_start if save_time < 1: time_str = str(round(save_time*1000,2))+"ms"