fix(config): preserve permissions during atomic save

This commit is contained in:
Xubin Ren committed 2026-07-21 17:33:39 +08:00
1 parent 28102382af
commit b2cf37da4a
2 files changed
+19

No files matched your search

+6
View File
@@ -5,6 +5,7 @@ import json
import os
import re
import shutil
import stat
import time
import uuid
from contextlib import suppress
@@ -454,8 +455,13 @@ def _cleanup_tool_result_buckets(root: Path, current_bucket: Path) -> None:
def _write_text_atomic(path: Path, content: str) -> None:
tmp = path.with_name(f".{path.name}.{uuid.uuid4().hex}.tmp")
existing_mode: int | None = None
with suppress(OSError):
existing_mode = stat.S_IMODE(path.stat().st_mode)
try:
with open(tmp, "w", encoding="utf-8") as f:
if existing_mode is not None:
os.chmod(tmp, existing_mode)
f.write(content)
f.flush()
os.fsync(f.fileno())