Skip to content

Commit f52131a

Browse files
committed
added delete_file
1 parent bbc3c10 commit f52131a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

codetide/agents/tide/utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from codetide.core.defaults import DEFAULT_ENCODING
22

33
from typing import List, Union
4+
import aiofiles.os
45
import aiofiles
56
import os
67
import re
@@ -114,3 +115,30 @@ def parse_steps_markdown(md: str):
114115
})
115116

116117
return steps
118+
119+
async def delete_file(file_path: str) -> bool:
120+
"""
121+
Safely delete a file asynchronously.
122+
123+
Args:
124+
file_path: Path to the file to delete
125+
126+
Returns:
127+
bool: True if file was deleted, False if it didn't exist
128+
129+
Raises:
130+
PermissionError: If lacking permissions to delete
131+
OSError: For other OS-related errors
132+
"""
133+
try:
134+
await aiofiles.os.remove(file_path)
135+
return True
136+
except FileNotFoundError:
137+
# File doesn't exist - consider this "success"
138+
return False
139+
except PermissionError:
140+
# Handle permission issues
141+
raise
142+
except OSError:
143+
# Handle other OS errors (disk full, etc.)
144+
raise

0 commit comments

Comments
 (0)