MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / _atomic_write_json

Function _atomic_write_json

src/config.py:109–125  ·  view source on GitHub ↗

Write JSON atomically via temp-file + rename, chmod 0600.

(path: Path, data: dict[str, Any])

Source from the content-addressed store, hash-verified

107
108
109def _atomic_write_json(path: Path, data: dict[str, Any]) -> None:
110 """Write JSON atomically via temp-file + rename, chmod 0600."""
111 path.parent.mkdir(parents=True, exist_ok=True)
112 fd, tmp = tempfile.mkstemp(dir=str(path.parent), suffix=".tmp")
113 try:
114 with os.fdopen(fd, "w", encoding="utf-8") as f:
115 json.dump(data, f, indent=2, ensure_ascii=False)
116 f.write("\n")
117 os.replace(tmp, str(path))
118 if os.name != "nt":
119 os.chmod(str(path), 0o600)
120 except Exception:
121 try:
122 os.unlink(tmp)
123 except OSError:
124 pass
125 raise
126
127
128# ---------------------------------------------------------------------------

Callers 7

test_creates_fileMethod · 0.90
save_globalMethod · 0.85
save_projectMethod · 0.85
save_localMethod · 0.85
update_project_entryFunction · 0.85

Calls 1

writeMethod · 0.45

Tested by 3

test_creates_fileMethod · 0.72