mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-29 21:08:53 -06:00
refactor: route atomic writes through one helper
This commit is contained in:
1 parent
856883f690
commit
434d660647
7 files changed
+59
-111
No files matched your search
@@ -25,7 +25,7 @@ from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from core.artifacts import set_plain_mode
|
||||
from core.artifacts import write_text_atomic
|
||||
|
||||
USER_AGENT = "retrobios-profile-sync/1.0"
|
||||
# Where fetched upstream files live, shared by every reader of this cache.
|
||||
@@ -401,15 +401,7 @@ def write_cache(target: Path, text: str) -> None:
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
except (FileExistsError, NotADirectoryError):
|
||||
return
|
||||
fd, scratch = tempfile.mkstemp(dir=str(target.parent), suffix=".part")
|
||||
try:
|
||||
with os.fdopen(fd, "w", encoding="utf-8") as fh:
|
||||
fh.write(text)
|
||||
set_plain_mode(scratch)
|
||||
os.replace(scratch, target)
|
||||
except OSError:
|
||||
Path(scratch).unlink(missing_ok=True)
|
||||
raise
|
||||
write_text_atomic(target, text)
|
||||
|
||||
|
||||
def fetch_file(
|
||||
|
||||
Reference in new issue
Block a user