Map SAB storage root safely
Only treat configured manual storage as Importarr-owned and map SAB container paths to local paths.
This commit is contained in:
@@ -26,7 +26,7 @@ def has_transient_part(path: Path) -> bool:
|
||||
return any(part in TRANSIENT_PARTS or any(token in part for token in TRANSIENT_PARTS) for part in path.parts)
|
||||
|
||||
|
||||
def classify_history_item(item: dict[str, Any], active_nzo_ids: set[str], category: str, download_root: Path, force_status: bool = False) -> Readiness:
|
||||
def classify_history_item(item: dict[str, Any], active_nzo_ids: set[str], category: str, download_root: Path, force_status: bool = False, sab_storage_root: Path | None = None) -> Readiness:
|
||||
nzo_id = str(item.get("nzo_id") or item.get("nzoid") or "")
|
||||
if not force_status and nzo_id and nzo_id in active_nzo_ids:
|
||||
return Readiness("processing", "SAB job is still present in queue")
|
||||
@@ -35,7 +35,10 @@ def classify_history_item(item: dict[str, Any], active_nzo_ids: set[str], catego
|
||||
storage_value = str(item.get("storage") or "")
|
||||
storage = Path(storage_value).resolve() if storage_value else None
|
||||
root = download_root.resolve()
|
||||
storage_in_root = bool(storage and (storage == root or root in storage.parents))
|
||||
sab_root = (sab_storage_root or download_root).resolve()
|
||||
storage_in_local_root = bool(storage and (storage == root or root in storage.parents))
|
||||
storage_in_sab_root = bool(storage and (storage == sab_root or sab_root in storage.parents))
|
||||
storage_in_root = storage_in_local_root or storage_in_sab_root
|
||||
if item_category != category and not storage_in_root:
|
||||
return Readiness("ignored", "SAB category/storage is not owned by Importarr", storage)
|
||||
if not force_status and status == "Failed":
|
||||
@@ -46,6 +49,8 @@ def classify_history_item(item: dict[str, Any], active_nzo_ids: set[str], catego
|
||||
return Readiness("unknown", "SAB completed item has no final storage")
|
||||
if not storage_in_root:
|
||||
return Readiness("ignored", "SAB storage is outside configured download root", storage)
|
||||
if storage_in_sab_root and not storage_in_local_root:
|
||||
storage = root / storage.relative_to(sab_root)
|
||||
if has_transient_part(storage):
|
||||
return Readiness("processing", "SAB storage path contains transient unpack/admin marker", storage)
|
||||
if force_status and status != "Completed":
|
||||
|
||||
Reference in New Issue
Block a user