MCPcopy Create free account
hub / github.com/deepelementlab/jupyter-studio / atomic_write_text

Function atomic_write_text

clawcode/clawcode/deepnote/utils.py:33–47  ·  view source on GitHub ↗

Write text atomically via a temp file and replace, cleaning up on failure.

(path: Path, content: str, encoding: str = "utf-8")

Source from the content-addressed store, hash-verified

31
32
33def atomic_write_text(path: Path, content: str, encoding: str = "utf-8") -> None:
34 """Write text atomically via a temp file and replace, cleaning up on failure."""
35 path = Path(path)
36 path.parent.mkdir(parents=True, exist_ok=True)
37 tmp = path.with_suffix(path.suffix + ".tmp")
38 try:
39 tmp.write_text(content, encoding=encoding)
40 tmp.replace(path)
41 except Exception:
42 if tmp.exists():
43 try:
44 tmp.unlink()
45 except OSError:
46 pass
47 raise

Callers 5

saveMethod · 0.85
_save_domain_metadataMethod · 0.85
write_pageMethod · 0.85
save_raw_sourceMethod · 0.85
rebuild_index_fileMethod · 0.85

Calls 2

replaceMethod · 0.80
existsMethod · 0.80

Tested by

no test coverage detected