Skip to content

Commit d783fcd

Browse files
committed
perf(backend_filesystem): Use comprehensions where to improve performance
1 parent 4c5c3a9 commit d783fcd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ardupilot_methodic_configurator/backend_filesystem.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,9 @@ def remove_created_files_and_vehicle_dir(self) -> str:
599599

600600
# delete all files in the vehicle directory and delete the vehicle directory
601601
errors: list[str] = []
602-
for item_path in vehicle_path.iterdir():
602+
603+
def safe_remove_item(item_path: Path) -> Optional[str]:
604+
"""Safely remove a file or directory, returning error message if failed."""
603605
try:
604606
# If the entry is a symlink, remove the link instead of recursing into the target
605607
if item_path.is_symlink():
@@ -608,9 +610,16 @@ def remove_created_files_and_vehicle_dir(self) -> str:
608610
shutil_rmtree(str(item_path))
609611
else:
610612
item_path.unlink()
613+
return None
611614
except OSError as e:
612615
logging_exception(_("Error removing %s"), item_path, e)
613-
errors.append(str(e))
616+
return str(e)
617+
618+
# Remove all items and collect errors
619+
for item_path in vehicle_path.iterdir():
620+
error = safe_remove_item(item_path)
621+
if error:
622+
errors.append(error)
614623

615624
# Try to remove the now-empty vehicle directory
616625
try:

0 commit comments

Comments
 (0)