Skip to content

Commit

Permalink
Store the file edit backup file in /tmp (#3958)
Browse files Browse the repository at this point in the history
  • Loading branch information
xingyaoww authored Sep 22, 2024
1 parent 714e46f commit 3435f1e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions openhands/runtime/plugins/agent_skills/file_ops/file_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 imported
if 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)

Expand Down Expand Up @@ -597,7 +597,9 @@ def subtract_strings(str1, str2) -> str:
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_str

except FileNotFoundError as e:
Expand Down

0 comments on commit 3435f1e

Please sign in to comment.