diff --git a/lbry/extras/daemon/storage.py b/lbry/extras/daemon/storage.py index ce242bfe0..1387f94a7 100644 --- a/lbry/extras/daemon/storage.py +++ b/lbry/extras/daemon/storage.py @@ -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 diff --git a/lbry/file/file_manager.py b/lbry/file/file_manager.py index fb841f401..ec18d273d 100644 --- a/lbry/file/file_manager.py +++ b/lbry/file/file_manager.py @@ -124,10 +124,17 @@ 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") - await self.storage.save_content_claim( - existing[0].stream_hash, outpoint - ) - await source_manager._update_content_claim(existing[0]) + 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 + ) + await source_manager._update_content_claim(existing[0]) updated_stream = existing[0] else: existing_for_claim_id = self.get_filtered(claim_id=txo.claim_id) diff --git a/tests/integration/datanetwork/test_file_commands.py b/tests/integration/datanetwork/test_file_commands.py index 8aafb60f0..15783f5f6 100644 --- a/tests/integration/datanetwork/test_file_commands.py +++ b/tests/integration/datanetwork/test_file_commands.py @@ -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):