MCPcopy Create free account
hub / github.com/FastLED/FastLED / safe_file_removal

Function safe_file_removal

ci/util/create_build_dir.py:215–259  ·  view source on GitHub ↗

Safely remove a file with retry logic. Args: file_path: Path to the file to remove max_retries: Maximum number of retry attempts Returns: True if removal was successful, False otherwise

(file_path: Path, max_retries: int)

Source from the content-addressed store, hash-verified

213
214
215def safe_file_removal(file_path: Path, max_retries: int) -> bool:
216 """
217 Safely remove a file with retry logic.
218
219 Args:
220 file_path: Path to the file to remove
221 max_retries: Maximum number of retry attempts
222
223 Returns:
224 True if removal was successful, False otherwise
225 """
226 if not file_path.exists():
227 return True
228
229 for attempt in range(max_retries):
230 try:
231 file_path.unlink()
232 locked_print(f"Successfully removed file {file_path}")
233 return True
234 except OSError as e:
235 if attempt == max_retries - 1:
236 locked_print(
237 f"Failed to remove file {file_path} after {max_retries} attempts: {e}"
238 )
239 return False
240
241 locked_print(
242 f"Failed to remove file {file_path} on attempt {attempt + 1}: {e}"
243 )
244
245 # Check if another process removed it
246 if not file_path.exists():
247 locked_print(f"File {file_path} was removed by another process")
248 return True
249
250 time.sleep(0.1 * (attempt + 1))
251
252 except KeyboardInterrupt as ki:
253 handle_keyboard_interrupt(ki)
254 raise
255 except Exception as e:
256 locked_print(f"Unexpected error removing file {file_path}: {e}")
257 return False
258
259 return False
260
261
262def create_build_dir(

Callers 1

create_build_dirFunction · 0.85

Calls 3

locked_printFunction · 0.90
unlinkMethod · 0.80

Tested by

no test coverage detected