Revert "tools: fix file_edit and file_write to write directly, not via temp+rename"

This reverts commit ce1688efb8.
This commit is contained in:
Levi Neely 2026-04-14 18:14:16 +02:00
parent ce1688efb8
commit 7999bd34a7
2 changed files with 15 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import sys
import os
import hashlib
import difflib
import tempfile
def marker_path(file_path):
h = hashlib.sha256(file_path.encode()).hexdigest()[:64]
@ -113,10 +114,13 @@ if err:
print(f"error: {err}")
sys.exit(1)
tmp = tempfile.NamedTemporaryFile(mode='w', dir=os.path.dirname(file_path) or '.', delete=False)
try:
with open(file_path, 'w') as f:
f.write(new_content)
except OSError as e:
tmp.write(new_content)
tmp.close()
os.replace(tmp.name, file_path)
except Exception as e:
os.unlink(tmp.name)
print(f"error: {e}")
sys.exit(1)

View File

@ -6,6 +6,7 @@ import sys
import os
import hashlib
import difflib
import tempfile
def marker_path(file_path):
h = hashlib.sha256(file_path.encode()).hexdigest()[:64]
@ -39,10 +40,14 @@ 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:
with open(file_path, 'w') as f:
f.write(content)
except OSError as e:
tmp.write(content)
tmp.close()
os.replace(tmp.name, file_path)
except Exception as e:
os.unlink(tmp.name)
print(f"error: {e}")
sys.exit(1)