fix zipseq not clearing zips
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -21,7 +21,7 @@ if not exist "%GET_STRUCT_DIR%" (
|
|||||||
)
|
)
|
||||||
|
|
||||||
for /f "usebackq delims=" %%I in (`powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
for /f "usebackq delims=" %%I in (`powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
||||||
"Set-StrictMode -Version Latest; $structDir = & '%GET_STRUCT_DIR%' -ProjectRoot '%PROJ_ROOT%'; if (-not $structDir) { throw \"Failed to get structDir from GetStructDir.ps1\" }; $pyPath = Join-Path $structDir 'zip_sequences.py'; if (-not (Test-Path -LiteralPath $pyPath)) { throw \"zip_sequences.py not found at $pyPath\" }; Write-Output $pyPath"`) do set "PY_SCRIPT=%%I"
|
"Set-StrictMode -Version Latest; $structDir = & '%GET_STRUCT_DIR%' -ProjectRoot '%PROJ_ROOT%'; if (-not $structDir) { throw \"Failed to get structDir from GetStructDir.ps1\" }; $pyPath = Join-Path $structDir 'zip_sequences.py'; if (-not (Test-Path -LiteralPath $pyPath)) { throw \"zip_sequences.py not found at $pyPath\" }; Write-Output $pyPath"`) do set "PY_SCRIPT=%%~I"
|
||||||
|
|
||||||
if not defined PY_SCRIPT (
|
if not defined PY_SCRIPT (
|
||||||
echo [ERROR] Unable to resolve zip_sequences.py path from config.
|
echo [ERROR] Unable to resolve zip_sequences.py path from config.
|
||||||
@@ -33,10 +33,12 @@ pushd "%PROJ_ROOT%" >nul 2>&1
|
|||||||
python "%PY_SCRIPT%" --verbose %*
|
python "%PY_SCRIPT%" --verbose %*
|
||||||
set "ERR=!ERRORLEVEL!"
|
set "ERR=!ERRORLEVEL!"
|
||||||
|
|
||||||
if not "!ERR!"=="0" (
|
popd >nul 2>&1
|
||||||
echo Failed to update render sequence archives (exit code !ERR!).
|
|
||||||
|
if !ERR! NEQ 0 (
|
||||||
|
echo Failed to update render sequence archives ^(exit code !ERR!^).
|
||||||
|
exit /b !ERR!
|
||||||
)
|
)
|
||||||
|
|
||||||
popd >nul 2>&1
|
exit /b 0
|
||||||
exit /b !ERR!
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
|
import traceback
|
||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Iterator, Sequence
|
from typing import Iterator, Sequence
|
||||||
@@ -888,6 +889,9 @@ def run_zip(requested_workers: int | None, *, verbose: bool) -> int:
|
|||||||
f"Summary: scanned {total_scanned}, quick-skipped {quick_skipped}, "
|
f"Summary: scanned {total_scanned}, quick-skipped {quick_skipped}, "
|
||||||
f"state-skipped {state_skipped}, empty {empty_dirs}, queued {queued}",
|
f"state-skipped {state_skipped}, empty {empty_dirs}, queued {queued}",
|
||||||
)
|
)
|
||||||
|
removed = cleanup_orphan_archives(verbose=verbose)
|
||||||
|
if removed:
|
||||||
|
log("zip", f"Removed {removed} orphan archive(s).", verbose=verbose)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
# Calculate RAM-aware worker count based on work items
|
# Calculate RAM-aware worker count based on work items
|
||||||
@@ -986,36 +990,83 @@ def run_expand(worker_count: int, *, verbose: bool) -> int:
|
|||||||
|
|
||||||
def cleanup_orphan_archives(*, verbose: bool) -> int:
|
def cleanup_orphan_archives(*, verbose: bool) -> int:
|
||||||
if not ARCHIVE_ROOT.exists():
|
if not ARCHIVE_ROOT.exists():
|
||||||
|
log("zip", "Archive root does not exist; nothing to clean up.", verbose_only=True, verbose=verbose)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
removed: list[Path] = []
|
removed: list[Path] = []
|
||||||
|
|
||||||
|
log("zip", f"Scanning for orphan archives in {ARCHIVE_ROOT.resolve()}", verbose_only=True, verbose=verbose)
|
||||||
|
|
||||||
# Look for both .zip and .7z archives
|
# Look for both .zip and .7z archives
|
||||||
archive_patterns = ["*.zip", "*.7z"]
|
archive_patterns = ["*.zip", "*.7z"]
|
||||||
for pattern in archive_patterns:
|
for pattern in archive_patterns:
|
||||||
for zip_path in ARCHIVE_ROOT.rglob(pattern):
|
try:
|
||||||
seq_dir = sequence_dir_for(zip_path)
|
for zip_path in ARCHIVE_ROOT.rglob(pattern):
|
||||||
if seq_dir.exists():
|
try:
|
||||||
continue
|
# Resolve to absolute paths for consistent checking
|
||||||
|
zip_path_abs = zip_path.resolve()
|
||||||
|
|
||||||
rel = zip_path.relative_to(ARCHIVE_ROOT)
|
# Calculate state path BEFORE checking/removing archive
|
||||||
log("zip", f"Removing orphan archive {rel}", verbose_only=True, verbose=verbose)
|
state_path = state_path_for(zip_path)
|
||||||
|
state_path_abs = state_path.resolve()
|
||||||
|
|
||||||
zip_path.unlink(missing_ok=True)
|
# Calculate sequence directory using sequence_dir_for
|
||||||
state_path = state_path_for(zip_path)
|
# This function works with paths relative to ARCHIVE_ROOT
|
||||||
if state_path.exists():
|
seq_dir = sequence_dir_for(zip_path)
|
||||||
state_path.unlink()
|
seq_dir_abs = seq_dir.resolve()
|
||||||
removed.append(zip_path)
|
|
||||||
|
# Check if sequence directory exists and is actually a directory
|
||||||
|
if seq_dir_abs.exists() and seq_dir_abs.is_dir():
|
||||||
|
log("zip", f"Archive {zip_path.relative_to(ARCHIVE_ROOT)} has matching sequence directory; keeping", verbose_only=True, verbose=verbose)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Sequence directory doesn't exist - this is an orphan archive
|
||||||
|
rel = zip_path.relative_to(ARCHIVE_ROOT)
|
||||||
|
log("zip", f"Removing orphan archive {rel}", verbose_only=False, verbose=verbose)
|
||||||
|
|
||||||
|
# Remove archive file
|
||||||
|
if zip_path_abs.exists():
|
||||||
|
zip_path_abs.unlink()
|
||||||
|
log("zip", f"Deleted archive: {rel}", verbose_only=True, verbose=verbose)
|
||||||
|
|
||||||
|
# Remove state file if it exists
|
||||||
|
if state_path_abs.exists():
|
||||||
|
state_path_abs.unlink()
|
||||||
|
state_rel = state_path.relative_to(ARCHIVE_ROOT)
|
||||||
|
log("zip", f"Removed orphan metadata {state_rel}", verbose_only=False, verbose=verbose)
|
||||||
|
|
||||||
|
removed.append(zip_path_abs)
|
||||||
|
except Exception as e:
|
||||||
|
# Log error but continue processing other archives
|
||||||
|
try:
|
||||||
|
rel = zip_path.relative_to(ARCHIVE_ROOT)
|
||||||
|
except:
|
||||||
|
rel = zip_path
|
||||||
|
log("zip", f"Error processing archive {rel}: {e}", verbose_only=True, verbose=verbose)
|
||||||
|
log("zip", f"Traceback: {traceback.format_exc()}", verbose_only=True, verbose=verbose)
|
||||||
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
log("zip", f"Error scanning for {pattern} archives: {e}", verbose_only=True, verbose=verbose)
|
||||||
|
log("zip", f"Traceback: {traceback.format_exc()}", verbose_only=True, verbose=verbose)
|
||||||
|
continue
|
||||||
|
|
||||||
if not removed:
|
if not removed:
|
||||||
|
log("zip", "No orphan archives found.", verbose_only=True, verbose=verbose)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
for parent in sorted({p.parent for p in removed}, key=lambda p: len(p.parts), reverse=True):
|
# Clean up empty parent directories
|
||||||
if not parent.exists():
|
archive_root_abs = ARCHIVE_ROOT.resolve()
|
||||||
|
for parent in sorted({p.resolve().parent for p in removed}, key=lambda p: len(p.parts), reverse=True):
|
||||||
|
parent_resolved = parent.resolve()
|
||||||
|
if not parent_resolved.exists():
|
||||||
continue
|
continue
|
||||||
while parent != ARCHIVE_ROOT and not any(parent.iterdir()):
|
try:
|
||||||
parent.rmdir()
|
while parent_resolved != archive_root_abs and not any(parent_resolved.iterdir()):
|
||||||
parent = parent.parent
|
parent_resolved.rmdir()
|
||||||
|
parent_resolved = parent_resolved.parent.resolve()
|
||||||
|
except OSError:
|
||||||
|
# Ignore errors when removing directories (might be in use)
|
||||||
|
pass
|
||||||
|
|
||||||
return len(removed)
|
return len(removed)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user