fix: give atomic writes the umask mode

mkstemp creates its scratch 0600 and os.replace kept that mode, so
database.json, the manifests, the packs, the recipe snapshots and the
large-file cache were readable by their owner only. set_plain_mode
gives the scratch 0o666 less the umask, as open() would, before each
rename. A test walks every function that renames a mkstemp file.
This commit is contained in:
Abdessamad Derraz committed 2026-10-21 06:09:55 +02:00
1 parent 66937d21d7
commit b8baf92f1d
9 files changed
+122 -2

No files matched your search

+3
View File
@@ -21,6 +21,8 @@ from dataclasses import dataclass
from datetime import datetime
from pathlib import Path
from artifacts import set_plain_mode
USER_AGENT = "retrobios-profile-sync/1.0"
# Where fetched upstream files live, shared by every reader of this cache.
CACHE_DIR = ".cache/upstream"
@@ -343,6 +345,7 @@ def write_cache(target: Path, text: str) -> None:
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)