refactor: route atomic writes through one helper

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:00:14 +01:00
1 parent 856883f690
commit 434d660647
7 files changed
+59 -111

No files matched your search

+2 -10
View File
@@ -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(