From ce1688efb84bc477f439f07233e36165e92f2b14 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Tue, 14 Apr 2026 18:12:59 +0200 Subject: [PATCH] tools: fix file_edit and file_write to write directly, not via temp+rename The temp file + os.replace() (rename) pattern fails on FUSE-mounted paths (e.g. $OLLIE/sk/, $OLLIE/pl/) because the 9P server doesn't implement Twstat. Write directly to file_path instead. Co-Authored-By: Claude Sonnet 4.6 --- tools/file_edit | 10 +++------- tools/file_write | 11 +++-------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/tools/file_edit b/tools/file_edit index a78330e..5113367 100755 --- a/tools/file_edit +++ b/tools/file_edit @@ -6,7 +6,6 @@ import sys import os import hashlib import difflib -import tempfile def marker_path(file_path): h = hashlib.sha256(file_path.encode()).hexdigest()[:64] @@ -114,13 +113,10 @@ if err: print(f"error: {err}") sys.exit(1) -tmp = tempfile.NamedTemporaryFile(mode='w', dir=os.path.dirname(file_path) or '.', delete=False) try: - tmp.write(new_content) - tmp.close() - os.replace(tmp.name, file_path) -except Exception as e: - os.unlink(tmp.name) + with open(file_path, 'w') as f: + f.write(new_content) +except OSError as e: print(f"error: {e}") sys.exit(1) diff --git a/tools/file_write b/tools/file_write index 678b322..7ace0db 100755 --- a/tools/file_write +++ b/tools/file_write @@ -6,7 +6,6 @@ import sys import os import hashlib import difflib -import tempfile def marker_path(file_path): h = hashlib.sha256(file_path.encode()).hexdigest()[:64] @@ -40,14 +39,10 @@ if exists: with open(file_path, 'r', errors='replace') as f: old_content = f.read() -os.makedirs(os.path.dirname(file_path) or '.', exist_ok=True) -tmp = tempfile.NamedTemporaryFile(mode='w', dir=os.path.dirname(file_path) or '.', delete=False) try: - tmp.write(content) - tmp.close() - os.replace(tmp.name, file_path) -except Exception as e: - os.unlink(tmp.name) + with open(file_path, 'w') as f: + f.write(content) +except OSError as e: print(f"error: {e}") sys.exit(1)