series management tuning and import archive extraction troubleshooting
This commit is contained in:
@@ -332,10 +332,25 @@ def _run_cmd(cmd: list[str]) -> tuple[int, str, str]:
|
||||
return p.returncode, p.stdout, p.stderr
|
||||
|
||||
|
||||
def _count_extracted_files(out_dir: str) -> int:
|
||||
"""Count all files (recursively) in the output directory."""
|
||||
count = 0
|
||||
for root, dirs, files in os.walk(out_dir):
|
||||
count += len(files)
|
||||
return count
|
||||
|
||||
|
||||
def extract_with_unar(archive_path: str, out_dir: str) -> None:
|
||||
os.makedirs(out_dir, exist_ok=True)
|
||||
rc, out, err = _run_cmd(["unar", "-o", out_dir, archive_path])
|
||||
if rc != 0:
|
||||
# Check if files were actually extracted (partial success)
|
||||
# unar may return non-zero even when most files extracted successfully
|
||||
extracted_files = _count_extracted_files(out_dir)
|
||||
if extracted_files > 0:
|
||||
# Partial extraction - log warning but continue
|
||||
log.warning(f"unar partial extraction (rc={rc}): {extracted_files} files extracted from {archive_path}")
|
||||
return
|
||||
raise ExtractError(f"unar failed (rc={rc})\nSTDOUT:\n{out}\nSTDERR:\n{err}")
|
||||
|
||||
|
||||
@@ -343,6 +358,12 @@ def extract_with_7z(archive_path: str, out_dir: str) -> None:
|
||||
os.makedirs(out_dir, exist_ok=True)
|
||||
rc, out, err = _run_cmd(["7z", "x", "-y", f"-o{out_dir}", archive_path])
|
||||
if rc != 0:
|
||||
# Check if files were actually extracted (partial success)
|
||||
extracted_files = _count_extracted_files(out_dir)
|
||||
if extracted_files > 0:
|
||||
# Partial extraction - log warning but continue
|
||||
log.warning(f"7z partial extraction (rc={rc}): {extracted_files} files extracted from {archive_path}")
|
||||
return
|
||||
raise ExtractError(f"7z failed (rc={rc})\nSTDOUT:\n{out}\nSTDERR:\n{err}")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user