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):
def _save_torrent(transaction):
transaction.execute(
"insert into torrent values (?, NULL, ?, ?)", (bt_infohash, length, name)
"insert or replace into torrent values (?, NULL, ?, ?)", (bt_infohash, length, name)
).fetchall()
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()
await self.db.run(_save_torrent)
# update corresponding ManagedEncryptedFileDownloader object

View file

@ -124,6 +124,13 @@ class FileManager:
raise ResolveError(f"stream for {existing[0].claim_id} collides with existing download {txo.claim_id}")
if existing:
log.info("claim contains a metadata only update to a stream we have")
if claim.stream.source.bt_infohash:
await self.storage.save_torrent_content_claim(
existing[0].identifier, outpoint, existing[0].torrent_length, existing[0].torrent_name
)
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
)

View file

@ -33,7 +33,9 @@ class FileCommands(CommandTestCase):
async def test_download_torrent(self):
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)
async def create_streams_in_range(self, *args, **kwargs):