From 57e45ea8587ecb1b0e0849c10ad8fa220a5bcb99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Fri, 22 May 2026 23:17:28 +0200 Subject: [PATCH] block file info for incomplete files --- pytorrent/services/rtorrent/files.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pytorrent/services/rtorrent/files.py b/pytorrent/services/rtorrent/files.py index 0876915..93cd6aa 100644 --- a/pytorrent/services/rtorrent/files.py +++ b/pytorrent/services/rtorrent/files.py @@ -59,10 +59,17 @@ def _torrent_file_remote_path(profile: dict, torrent_hash: str, index: int) -> t if selected is 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}") + base = _remote_clean_path(_torrent_data_path(c, torrent_hash)) 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: path = _remote_join(base, rel) return selected, path