check if packages dir exists before deleting

This commit is contained in:
Jason2866
2025-07-07 19:02:58 +02:00
committed by GitHub
parent 2927017d56
commit 76886abd75
+8 -6
View File
@@ -154,12 +154,14 @@ class Espressif32Platform(PlatformBase):
tool_path = os.path.join(self.packages_dir, tool_name) tool_path = os.path.join(self.packages_dir, tool_name)
# Remove all directories containing '@' in their name # Remove all directories containing '@' in their name
try: try:
for item in os.listdir(self.packages_dir): if os.path.exists(self.packages_dir) and os.path.isdir(self.packages_dir):
if '@' in item and item.startswith(tool_name): for item in os.listdir(self.packages_dir):
item_path = os.path.join(self.packages_dir, item) if '@' in item and item.startswith(tool_name):
if os.path.isdir(item_path): item_path = os.path.join(self.packages_dir, item)
safe_remove_directory(item_path) if os.path.isdir(item_path):
logger.debug(f"Removed directory with '@' in name: {item_path}") safe_remove_directory(item_path)
logger.debug(f"Removed directory with '@' in name: {item_path}")
except OSError as e: except OSError as e:
logger.error(f"Error scanning packages directory for '@' directories: {e}") logger.error(f"Error scanning packages directory for '@' directories: {e}")