From 4cc1c56f754659c6d67bed444f6be0c39d82ac15 Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Fri, 5 Nov 2021 19:54:13 -0500 Subject: [PATCH] Fix bugs in `db' module --- src/disk_jumble/db.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/disk_jumble/db.py b/src/disk_jumble/db.py index 34c24b6..61bb2fd 100644 --- a/src/disk_jumble/db.py +++ b/src/disk_jumble/db.py @@ -92,7 +92,7 @@ class Wrapper: incomplete_edge as ( -- join up incomplete piece info and precompute where the hasher left off within the entity select - verify_id, seq, entity_id, hasher_state, + verify_id, seq, slab.entity_id, hasher_state, entity_offset + (upper(c.disk_sectors) - lower(slab.disk_sectors)) * sector_size as end_off from diskjumble.verify_piece_incomplete @@ -106,20 +106,20 @@ class Wrapper: where seq >= all (select seq from diskjumble.verify_piece_content where verify_id = p.verify_id) ) select - slab_id, disk_id, disk_sectors, entity_id, entity_offset, crypt_key, verify_id, seq, end_off, + slab_id, disk_id, disk_sectors, slab.entity_id, entity_offset, crypt_key, verify_id, seq, end_off, hasher_state from diskjumble.slab natural left join diskjumble.disk left join incomplete_edge on incomplete_edge.entity_id = slab.entity_id - and incomplete_edge.end_off % sector_size == 0 + and incomplete_edge.end_off %% sector_size = 0 and incomplete_edge.end_off <@ int8range( slab.entity_offset, slab.entity_offset + (upper(disk_sectors) - lower(disk_sectors)) * sector_size ) where disk_id = %s - order by entity_id, entity_offset, slab_id + order by slab.entity_id, entity_offset, slab_id ; """ with self.conn.cursor() as cursor: @@ -136,7 +136,7 @@ class Wrapper: yield (slab, hasher_ref) - def get_torrent_info(self, disk_id: int) -> Mapping[bytes, bytes]: + def get_torrent_info(self, disk_id: int) -> Iterable[tuple[bytes, bytes]]: stmt = """ with hashed as ( select digest(info, 'sha1') as info_hash, info @@ -152,7 +152,7 @@ class Wrapper: with self.conn.cursor() as cursor: cursor.execute(stmt, (disk_id,)) for (info_hash, info) in cursor: - yield (info_hash, info) + yield (bytes(info_hash), bytes(info)) def insert_verify_piece(self, ts: dt.datetime, entity_id: bytes, piece_num: int) -> int: """Insert new verify piece, returning the ID of the inserted row.""" -- 2.30.2