π OpenHands: AI-Driven Development
Store the file edit backup file in `/tmp` (#3958)
Xingyao Wang3435f1e5d8d2
diff --git a/openhands/runtime/plugins/agent_skills/file_ops/file_ops.py b/openhands/runtime/plugins/agent_skills/file_ops/file_ops.pyindex e4d4283008..6e37c15a2e 100644--- a/openhands/runtime/plugins/agent_skills/file_ops/file_ops.py+++ b/openhands/runtime/plugins/agent_skills/file_ops/file_ops.py@@ -510,11 +510,11 @@ def _edit_file_impl(# NOTE: we need to get env var inside this function# because the env var will be set AFTER the agentskills is importedif enable_auto_lint:- # BACKUP the original file- original_file_backup_path = os.path.join(- os.path.dirname(file_name),- f'.backup.{os.path.basename(file_name)}',- )+ # Generate a random temporary file path+ suffix = os.path.splitext(file_name)[1]+ with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as tfile:+ original_file_backup_path = tfile.name+with open(original_file_backup_path, 'w') as f:f.writelines(lines)@@ -597,7 +597,9 @@ def _edit_file_impl(file_name, 'w') as fout:fout.write(fin.read())- os.remove(original_file_backup_path)++ # Don't forget to remove the temporary file after you're done+ os.unlink(original_file_backup_path)return ret_strexcept FileNotFoundError as e: