diff --git a/web_server.py b/web_server.py index 9ea6db4d..30a67259 100644 --- a/web_server.py +++ b/web_server.py @@ -1109,25 +1109,33 @@ def _register_automation_handlers(): _update_automation_progress(automation_id, log_line=f'Empty directories: removed {dirs_removed}', log_type='success' if dirs_removed else 'info') - # --- 4. Clear staging folder --- - _update_automation_progress(automation_id, phase='Clearing staging folder...', progress=60) + # --- 4. Sweep empty staging directories --- + _update_automation_progress(automation_id, phase='Sweeping staging folder...', progress=60) staging_path = _get_staging_path() s_removed = 0 if os.path.isdir(staging_path): - for f in os.listdir(staging_path): - fp = os.path.join(staging_path, f) + for dirpath, _dirnames, _filenames in os.walk(staging_path, topdown=False): + if os.path.normpath(dirpath) == os.path.normpath(staging_path): + continue try: - if os.path.isfile(fp): - os.remove(fp) - s_removed += 1 - elif os.path.isdir(fp): - _shutil.rmtree(fp) + entries = os.listdir(dirpath) + except OSError: + continue + visible = [e for e in entries if not e.startswith('.')] + if not visible: + for hidden in entries: + try: + os.remove(os.path.join(dirpath, hidden)) + except Exception: + pass + try: + os.rmdir(dirpath) s_removed += 1 - except Exception: - pass - steps.append(f'Staging: removed {s_removed} items') + except OSError: + pass + steps.append(f'Staging: removed {s_removed} empty directories') _update_automation_progress(automation_id, - log_line=f'Staging: removed {s_removed} items', log_type='success' if s_removed else 'info') + log_line=f'Staging: removed {s_removed} empty directories', log_type='success' if s_removed else 'info') # --- 5. Clean search history --- _update_automation_progress(automation_id, phase='Cleaning search history...', progress=80) diff --git a/webui/static/script.js b/webui/static/script.js index da87703e..c6e0f2aa 100644 --- a/webui/static/script.js +++ b/webui/static/script.js @@ -17583,7 +17583,7 @@ const TOOL_HELP_CONTENT = {
  • Clear Quarantine — permanently deletes all quarantined files
  • Clear Download Queue — removes completed, errored, and cancelled downloads from Soulseek
  • Sweep Empty Directories — removes empty folders left behind in the downloads directory
  • -
  • Clear Staging Folder — deletes all files and folders from the import staging area
  • +
  • Sweep Staging Folder — removes empty directories from the import staging area
  • Clean Search History — trims old Soulseek search queries
  • @@ -47483,7 +47483,7 @@ const _RESULT_DISPLAY_MAP = { ], 'full_cleanup': [ { key: 'quarantine_removed', label: 'Quarantine Removed' }, - { key: 'staging_removed', label: 'Staging Removed' }, + { key: 'staging_removed', label: 'Staging Dirs Removed' }, { key: 'total_removed', label: 'Total Items Removed' }, ], };