mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 14:54: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=[])
|
return Roster(real_path, players=[])
|
||||||
|
|
||||||
def save(self) -> None:
|
def save(self) -> None:
|
||||||
self.path.parent.mkdir(parents=True, exist_ok=True)
|
old_path = self.path.with_name(self.path.name + ".old")
|
||||||
self.path.write_bytes(pickle.dumps(self.players))
|
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