Retire the section-headers decision, reject an interrupt without a question, and name file_writes by what it does

This commit is contained in:
2026-09-28 16:46:18 +02:00
parent 9bfb2fe173
commit b40893bc70
9 changed files with 10 additions and 13 deletions
+25
View File
@@ -0,0 +1,25 @@
import json
import os
def make_private(folder):
mask = os.umask(0o077)
try:
os.makedirs(folder, exist_ok=True)
finally:
os.umask(mask)
def replace_json(path, data, **dump):
staged = f"{path}.{os.getpid()}"
try:
mode = os.stat(path).st_mode & 0o7777 if os.path.exists(path) else 0o600
with open(os.open(staged, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600), "w", encoding="utf-8") as handle:
os.fchmod(handle.fileno(), mode)
json.dump(data, handle, **dump)
os.replace(staged, path)
except OSError as failure:
if os.path.exists(staged):
os.remove(staged)
return failure
return None