From d1890c768c4af18d330ae8bf8c4ebcb237baef18 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Mon, 9 Mar 2026 17:10:35 -0700 Subject: [PATCH] cleanup staging folder same as download folder --- web_server.py | 34 +++++++++++++++++++++------------- webui/static/script.js | 4 ++-- 2 files changed, 23 insertions(+), 15 deletions(-) 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 = {