Skip to content

Commit 8ee272a

Browse files
authored
Fix performance lag: directory removal with iterdir
1 parent cd52c8c commit 8ee272a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

platform.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,11 @@ def safe_remove_directory_pattern(base_path: Union[str, Path], pattern: str) ->
160160
base_path = Path(base_path)
161161
if not base_path.exists():
162162
return True
163-
# Find all directories matching the pattern in the base directory
164-
for item in base_path.rglob("*"):
165-
if fnmatch.fnmatch(item.name, pattern):
163+
for item in base_path.iterdir():
164+
if item.is_dir() and fnmatch.fnmatch(item.name, pattern):
166165
if item.is_symlink():
167166
item.unlink()
168-
elif item.is_dir():
167+
else:
169168
shutil.rmtree(item)
170169
logger.debug(f"Directory removed: {item}")
171170
return True

0 commit comments

Comments
 (0)