(path: str, content: str)
| 35 | |
| 36 | |
| 37 | def atomic_write(path: str, content: str) -> None: |
| 38 | directory = os.path.dirname(path) or "." |
| 39 | fd, tmp_path = tempfile.mkstemp(prefix=".doc-update.", dir=directory, text=True) |
| 40 | try: |
| 41 | with os.fdopen(fd, "w", encoding="utf-8", newline="\n") as f: |
| 42 | f.write(content) |
| 43 | os.replace(tmp_path, path) |
| 44 | finally: |
| 45 | if os.path.exists(tmp_path): |
| 46 | os.unlink(tmp_path) |
| 47 | |
| 48 | |
| 49 | def main() -> int: |