fix not knowing a torrent exists

This commit is contained in:
Victor Shyba 2020-02-25 18:18:48 -03:00
parent 3f718e6efc
commit f602541ede
3 changed files with 16 additions and 7 deletions

View file

@ -805,10 +805,10 @@ class SQLiteStorage(SQLiteMixin):
async def save_torrent_content_claim(self, bt_infohash, claim_outpoint, length, name): async def save_torrent_content_claim(self, bt_infohash, claim_outpoint, length, name):
def _save_torrent(transaction): def _save_torrent(transaction):
transaction.execute( transaction.execute(
"insert into torrent values (?, NULL, ?, ?)", (bt_infohash, length, name) "insert or replace into torrent values (?, NULL, ?, ?)", (bt_infohash, length, name)
).fetchall() ).fetchall()
transaction.execute( transaction.execute(
"insert into content_claim values (NULL, ?, ?)", (bt_infohash, claim_outpoint) "insert or replace into content_claim values (NULL, ?, ?)", (bt_infohash, claim_outpoint)
).fetchall() ).fetchall()
await self.db.run(_save_torrent) await self.db.run(_save_torrent)
# update corresponding ManagedEncryptedFileDownloader object # update corresponding ManagedEncryptedFileDownloader object

View file

@ -124,10 +124,17 @@ class FileManager:
raise ResolveError(f"stream for {existing[0].claim_id} collides with existing download {txo.claim_id}") raise ResolveError(f"stream for {existing[0].claim_id} collides with existing download {txo.claim_id}")
if existing: if existing:
log.info("claim contains a metadata only update to a stream we have") log.info("claim contains a metadata only update to a stream we have")
await self.storage.save_content_claim( if claim.stream.source.bt_infohash:
existing[0].stream_hash, outpoint await self.storage.save_torrent_content_claim(
) existing[0].identifier, outpoint, existing[0].torrent_length, existing[0].torrent_name
await source_manager._update_content_claim(existing[0]) )
claim_info = await self.storage.get_content_claim_for_torrent(existing[0].identifier)
existing[0].set_claim(claim_info, claim)
else:
await self.storage.save_content_claim(
existing[0].stream_hash, outpoint
)
await source_manager._update_content_claim(existing[0])
updated_stream = existing[0] updated_stream = existing[0]
else: else:
existing_for_claim_id = self.get_filtered(claim_id=txo.claim_id) existing_for_claim_id = self.get_filtered(claim_id=txo.claim_id)

View file

@ -33,7 +33,9 @@ class FileCommands(CommandTestCase):
async def test_download_torrent(self): async def test_download_torrent(self):
await self.initialize_torrent() await self.initialize_torrent()
await self.out(self.daemon.jsonrpc_get('torrent')) self.assertNotIn('error', await self.out(self.daemon.jsonrpc_get('torrent')))
self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1)
self.assertNotIn('error', await self.out(self.daemon.jsonrpc_get('torrent')))
self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1) self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1)
async def create_streams_in_range(self, *args, **kwargs): async def create_streams_in_range(self, *args, **kwargs):