Fixed saving known destination when on-disk storage file has become corrupted

This commit is contained in:
Mark Qvist 2024-02-29 23:23:41 +01:00
parent c2c3a144d2
commit 05e97ac0db
1 changed files with 9 additions and 4 deletions

View File

@ -145,9 +145,12 @@ class Identity:
except: except:
pass pass
try:
for destination_hash in storage_known_destinations: for destination_hash in storage_known_destinations:
if not destination_hash in Identity.known_destinations: if not destination_hash in Identity.known_destinations:
Identity.known_destinations[destination_hash] = storage_known_destinations[destination_hash] Identity.known_destinations[destination_hash] = storage_known_destinations[destination_hash]
except Exception as e:
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_DEBUG) RNS.log("Saving "+str(len(Identity.known_destinations))+" known destinations to storage...", RNS.LOG_DEBUG)
file = open(RNS.Reticulum.storagepath+"/known_destinations","wb") file = open(RNS.Reticulum.storagepath+"/known_destinations","wb")
@ -164,6 +167,7 @@ class Identity:
except Exception as e: except Exception as e:
RNS.log("Error while saving known destinations to disk, the contained exception was: "+str(e), RNS.LOG_ERROR) RNS.log("Error while saving known destinations to disk, the contained exception was: "+str(e), RNS.LOG_ERROR)
RNS.trace_exception(e)
Identity.saving_known_destinations = False Identity.saving_known_destinations = False
@ -181,7 +185,8 @@ class Identity:
Identity.known_destinations[known_destination] = loaded_known_destinations[known_destination] Identity.known_destinations[known_destination] = loaded_known_destinations[known_destination]
RNS.log("Loaded "+str(len(Identity.known_destinations))+" known destination from storage", RNS.LOG_VERBOSE) RNS.log("Loaded "+str(len(Identity.known_destinations))+" known destination from storage", RNS.LOG_VERBOSE)
except:
except Exception as e:
RNS.log("Error loading known destinations from disk, file will be recreated on exit", RNS.LOG_ERROR) RNS.log("Error loading known destinations from disk, file will be recreated on exit", RNS.LOG_ERROR)
else: else:
RNS.log("Destinations file does not exist, no known destinations loaded", RNS.LOG_VERBOSE) RNS.log("Destinations file does not exist, no known destinations loaded", RNS.LOG_VERBOSE)