Fix verify bugs
authorJakob Cornell <jakob+gpg@jcornell.net>
Sun, 17 Apr 2022 21:48:44 +0000 (16:48 -0500)
committerJakob Cornell <jakob+gpg@jcornell.net>
Sun, 17 Apr 2022 21:52:14 +0000 (16:52 -0500)
disk_jumble/src/disk_jumble/verify.py

index 60a53e5dd12891a6b2067f3034504d3abdb7368e..e9faef52836cde39c836c7eb3a7fa52dc3762e21 100644 (file)
@@ -89,7 +89,10 @@ def _get_v1_worklist(conn, disk_id: int, block_ranges: List[NumericRange]) -> Li
                """,
                (disk_id, block_ranges)
        )
-       infos = [_TorrentInfo.build(id_, info) for (id_, info) in cursor]
+       infos = [
+               _TorrentInfo.build(bytes(id_), bencode.decode(bytes(info)))
+               for (id_, info) in cursor
+       ]
 
        for i in infos:
                assert i.piece_length % BLOCK_SIZE == 0, f"entity {i.id.hex()} has invalid piece length"
@@ -153,13 +156,14 @@ def _get_v1_worklist(conn, disk_id: int, block_ranges: List[NumericRange]) -> Li
                if any(crypt_key is not None for (*_, crypt_key) in rows):
                        raise NotImplementedError("verify of encrypted data")
 
-               for (piece_num, ranges) in itertools.groupby(rows, lambda t: t[0]):
+               for (piece_num, piece_rows) in itertools.groupby(rows, lambda t: t[0]):
+                       block_ranges = [range(r.lower, r.upper) for (r, _) in piece_rows]
                        run = _V1Run(
                                entity_id = info.id,
                                entity_length = info.length,
                                piece_length = info.piece_length,
                                piece_num = piece_num,
-                               block_ranges = [range(r.lower, r.upper) for r in ranges],
+                               block_ranges = block_ranges,
                                hash = info.hashes[piece_num],
                        )
 
@@ -237,13 +241,13 @@ def _get_v2_worklist(conn, disk_id: int, block_ranges: List[NumericRange]) -> Li
 
        return [
                _V2Run(
-                       entity_id = entity_id,
+                       entity_id = bytes(entity_id),
                        entity_length = entity_length,
                        piece_num = piece_num,
                        block_ranges = [range(block, block + 1)],
-                       hash = hash_,
+                       hash = bytes(hash_),
                )
-               for (entity_id, entity_length, piece_num, block, entity_length, hash_, crypt_key) in rows
+               for (entity_id, entity_length, piece_num, block, entity_length, hash_, _) in rows
        ]