block file info for incomplete files

This commit is contained in:
Mateusz Gruszczyński
2026-05-22 23:17:28 +02:00
parent c69142e328
commit 57e45ea858

View File

@@ -59,10 +59,17 @@ def _torrent_file_remote_path(profile: dict, torrent_hash: str, index: int) -> t
if selected is None: if selected is None:
available = ", ".join(str(f.get("index")) for f in files[:20]) or "none" available = ", ".join(str(f.get("index")) for f in files[:20]) or "none"
raise ValueError(f"File index {index} not found. Available indexes: {available}") raise ValueError(f"File index {index} not found. Available indexes: {available}")
base = _remote_clean_path(_torrent_data_path(c, torrent_hash)) base = _remote_clean_path(_torrent_data_path(c, torrent_hash))
rel = str(selected.get("path") or "").lstrip("/") rel = str(selected.get("path") or "").lstrip("/")
if len(files) == 1 and base and not base.endswith("/"):
path = base # Note: rTorrent can report d.base_path as either the payload file or the
# containing data directory for a one-file torrent. Keep both existing
# layouts working and avoid treating a directory as the media file.
if len(files) == 1 and base and rel:
base_name = posixpath.basename(base.rstrip("/"))
rel_name = posixpath.basename(rel.rstrip("/"))
path = base if base_name == rel_name else _remote_join(base, rel)
else: else:
path = _remote_join(base, rel) path = _remote_join(base, rel)
return selected, path return selected, path