Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
515599f2d4 | ||
|
|
b67ca18403 | ||
|
|
6446846ee8 | ||
|
|
c717aea394 |
+6
-2
@@ -11,8 +11,12 @@ CMD ["python", "-m", "unittest", "discover", "-s", "tests", "-v"]
|
|||||||
|
|
||||||
FROM python:3.11-slim
|
FROM python:3.11-slim
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
|
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
|
||||||
RUN groupadd --gid 1001 archive-control \
|
RUN if ! getent group 1001 >/dev/null; then \
|
||||||
&& useradd --uid 1001 --gid 1001 --no-create-home archive-control
|
groupadd --gid 1001 archive-control; \
|
||||||
|
fi \
|
||||||
|
&& if ! getent passwd 1001 >/dev/null; then \
|
||||||
|
useradd --uid 1001 --gid 1001 --no-create-home archive-control; \
|
||||||
|
fi
|
||||||
COPY --from=builder /wheels /wheels
|
COPY --from=builder /wheels /wheels
|
||||||
RUN pip install --no-cache-dir /wheels/*.whl && rm -rf /wheels
|
RUN pip install --no-cache-dir /wheels/*.whl && rm -rf /wheels
|
||||||
USER 1001:1001
|
USER 1001:1001
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "archive-clients"
|
name = "archive-clients"
|
||||||
version = "0.1.16"
|
version = "0.1.19"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
dependencies = ["protobuf==7.35.1", "websockets==16.0"]
|
dependencies = ["protobuf==7.35.1", "websockets==16.0"]
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ def _v1_files(info: dict[bytes, Any]) -> list[MetaFile]:
|
|||||||
components = [name] + [_component(part) for part in raw_path]
|
components = [name] + [_component(part) for part in raw_path]
|
||||||
result.append(MetaFile(
|
result.append(MetaFile(
|
||||||
"/".join(components), _length(item.get(b"length")),
|
"/".join(components), _length(item.get(b"length")),
|
||||||
_padding(item),
|
_padding(item) or _bitcomet_padding_name(components[-1]),
|
||||||
))
|
))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -223,3 +223,13 @@ def _length(value: Any) -> int:
|
|||||||
def _padding(value: dict[bytes, Any]) -> bool:
|
def _padding(value: dict[bytes, Any]) -> bool:
|
||||||
attributes = value.get(b"attr", b"")
|
attributes = value.get(b"attr", b"")
|
||||||
return isinstance(attributes, bytes) and b"p" in attributes
|
return isinstance(attributes, bytes) and b"p" in attributes
|
||||||
|
|
||||||
|
|
||||||
|
def _bitcomet_padding_name(component: str) -> bool:
|
||||||
|
"""Recognize BitComet's legacy padding-file convention.
|
||||||
|
|
||||||
|
Such v1 torrents often omit the standard ``attr=p`` flag, but
|
||||||
|
qBittorrent/libtorrent still hides these synthetic entries from its file
|
||||||
|
API. The exact reserved prefix is the interoperable marker.
|
||||||
|
"""
|
||||||
|
return component.startswith("_____padding_file_")
|
||||||
|
|||||||
@@ -91,12 +91,21 @@ def normalize_resource(
|
|||||||
observed_at: datetime | None = None,
|
observed_at: datetime | None = None,
|
||||||
) -> NormalizedResource:
|
) -> NormalizedResource:
|
||||||
metainfo = decode_metainfo(metainfo_bytes)
|
metainfo = decode_metainfo(metainfo_bytes)
|
||||||
if len(raw_files) != len(metainfo.files):
|
# qBittorrent/libtorrent may omit torrent padding files from
|
||||||
|
# /torrents/files while keeping them in the exported metainfo.
|
||||||
|
visible_metainfo_files = tuple(
|
||||||
|
item for item in metainfo.files if not item.padding
|
||||||
|
)
|
||||||
|
if len(raw_files) == len(metainfo.files):
|
||||||
|
matched_metainfo_files = metainfo.files
|
||||||
|
elif len(raw_files) == len(visible_metainfo_files):
|
||||||
|
matched_metainfo_files = visible_metainfo_files
|
||||||
|
else:
|
||||||
raise ResourceError("qBittorrent and metainfo file counts differ")
|
raise ResourceError("qBittorrent and metainfo file counts differ")
|
||||||
files = []
|
files = []
|
||||||
canonical = True
|
canonical = True
|
||||||
for expected_index, (raw, meta_file) in enumerate(
|
for expected_index, (raw, meta_file) in enumerate(
|
||||||
zip(raw_files, metainfo.files, strict=True)
|
zip(raw_files, matched_metainfo_files, strict=True)
|
||||||
):
|
):
|
||||||
index = _integer(raw.get("index"), "file index")
|
index = _integer(raw.get("index"), "file index")
|
||||||
if index != expected_index:
|
if index != expected_index:
|
||||||
|
|||||||
@@ -118,6 +118,47 @@ class ResourceTests(unittest.TestCase):
|
|||||||
self.assertEqual(root.available_file_count, 1)
|
self.assertEqual(root.available_file_count, 1)
|
||||||
self.assertEqual(root.available_logical_bytes, 3)
|
self.assertEqual(root.available_logical_bytes, 3)
|
||||||
|
|
||||||
|
def test_qbittorrent_hidden_padding_files_are_normalized(self):
|
||||||
|
info = {
|
||||||
|
b"files": [
|
||||||
|
{b"length": 3, b"path": [b"first.bin"]},
|
||||||
|
{
|
||||||
|
b"length": 5,
|
||||||
|
b"path": [b"_____padding_file_5"],
|
||||||
|
},
|
||||||
|
{b"length": 7, b"path": [b"last.bin"]},
|
||||||
|
],
|
||||||
|
b"name": b"with-padding",
|
||||||
|
b"piece length": 16384,
|
||||||
|
b"pieces": b"x" * 20,
|
||||||
|
}
|
||||||
|
metainfo = encode({b"info": info})
|
||||||
|
torrent_hash = hashlib.sha1(encode(info)).hexdigest()
|
||||||
|
normalized = normalize_resource(
|
||||||
|
{
|
||||||
|
"hash": torrent_hash,
|
||||||
|
"name": "with-padding",
|
||||||
|
"state": "stalledUP",
|
||||||
|
},
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"index": 0, "name": "with-padding/first.bin",
|
||||||
|
"size": 3, "completed": 3, "priority": 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 1, "name": "with-padding/last.bin",
|
||||||
|
"size": 7, "completed": 7, "priority": 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
metainfo,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
[item.canonical_path for item in normalized.files],
|
||||||
|
["with-padding/first.bin", "with-padding/last.bin"],
|
||||||
|
)
|
||||||
|
self.assertEqual(normalized.summary.total_file_count, 2)
|
||||||
|
self.assertEqual(normalized.summary.selected_complete_bytes, 10)
|
||||||
|
|
||||||
def test_noncanonical_and_unsafe_paths_are_distinct(self):
|
def test_noncanonical_and_unsafe_paths_are_distinct(self):
|
||||||
info = {
|
info = {
|
||||||
b"length": 3,
|
b"length": 3,
|
||||||
|
|||||||
Reference in New Issue
Block a user