mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
roster: improve saving safety
This commit is contained in:
+7
-2
@@ -20,5 +20,10 @@ class Roster:
|
||||
return Roster(real_path, players=[])
|
||||
|
||||
def save(self) -> None:
|
||||
self.path.parent.mkdir(parents=True, exist_ok=True)
|
||||
self.path.write_bytes(pickle.dumps(self.players))
|
||||
old_path = self.path.with_name(self.path.name + ".old")
|
||||
tmp_path = self.path.with_name(self.path.name + ".new")
|
||||
tmp_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
tmp_path.write_bytes(pickle.dumps(self.players))
|
||||
if self.path.exists():
|
||||
self.path.rename(old_path)
|
||||
tmp_path.rename(self.path)
|
||||
|
||||
Reference in New Issue
Block a user