forked from LBRYCommunity/lbry-sdk
fix and test delete with torrents
This commit is contained in:
parent
ce1eabaed6
commit
a7c2408c0a
4 changed files with 18 additions and 7 deletions
|
@ -283,4 +283,4 @@ class FileManager:
|
||||||
|
|
||||||
async def delete(self, source: ManagedDownloadSource, delete_file=False):
|
async def delete(self, source: ManagedDownloadSource, delete_file=False):
|
||||||
for manager in self.source_managers.values():
|
for manager in self.source_managers.values():
|
||||||
return await manager.delete(source, delete_file)
|
await manager.delete(source, delete_file)
|
||||||
|
|
|
@ -231,12 +231,14 @@ class StreamManager(SourceManager):
|
||||||
return stream
|
return stream
|
||||||
|
|
||||||
async def delete(self, source: ManagedDownloadSource, delete_file: Optional[bool] = False):
|
async def delete(self, source: ManagedDownloadSource, delete_file: Optional[bool] = False):
|
||||||
if source.sd_hash in self.running_reflector_uploads:
|
if not isinstance(source, ManagedStream):
|
||||||
self.running_reflector_uploads[source.sd_hash].cancel()
|
return
|
||||||
|
if source.identifier in self.running_reflector_uploads:
|
||||||
|
self.running_reflector_uploads[source.identifier].cancel()
|
||||||
source.stop_tasks()
|
source.stop_tasks()
|
||||||
if source.sd_hash in self.streams:
|
if source.identifier in self.streams:
|
||||||
del self.streams[source.sd_hash]
|
del self.streams[source.identifier]
|
||||||
blob_hashes = [source.sd_hash] + [b.blob_hash for b in source.descriptor.blobs[:-1]]
|
blob_hashes = [source.identifier] + [b.blob_hash for b in source.descriptor.blobs[:-1]]
|
||||||
await self.blob_manager.delete_blobs(blob_hashes, delete_from_db=False)
|
await self.blob_manager.delete_blobs(blob_hashes, delete_from_db=False)
|
||||||
await self.storage.delete_stream(source.descriptor)
|
await self.storage.delete_stream(source.descriptor)
|
||||||
if delete_file and source.output_file_exists:
|
if delete_file and source.output_file_exists:
|
||||||
|
|
|
@ -63,6 +63,11 @@ class TorrentHandle:
|
||||||
self.size = 0
|
self.size = 0
|
||||||
self.total_wanted_done = 0
|
self.total_wanted_done = 0
|
||||||
self.name = ''
|
self.name = ''
|
||||||
|
self.tasks = []
|
||||||
|
|
||||||
|
def stop_tasks(self):
|
||||||
|
while self.tasks:
|
||||||
|
self.tasks.pop().cancel()
|
||||||
|
|
||||||
def _show_status(self):
|
def _show_status(self):
|
||||||
# fixme: cleanup
|
# fixme: cleanup
|
||||||
|
@ -177,12 +182,13 @@ class TorrentSession:
|
||||||
await self._loop.run_in_executor(
|
await self._loop.run_in_executor(
|
||||||
self._executor, self._add_torrent, btih, download_path
|
self._executor, self._add_torrent, btih, download_path
|
||||||
)
|
)
|
||||||
self._loop.create_task(self._handles[btih].status_loop())
|
self._handles[btih].tasks.append(self._loop.create_task(self._handles[btih].status_loop()))
|
||||||
await self._handles[btih].metadata_completed.wait()
|
await self._handles[btih].metadata_completed.wait()
|
||||||
|
|
||||||
def remove_torrent(self, btih, remove_files=False):
|
def remove_torrent(self, btih, remove_files=False):
|
||||||
if btih in self._handles:
|
if btih in self._handles:
|
||||||
handle = self._handles[btih]
|
handle = self._handles[btih]
|
||||||
|
handle.stop_tasks()
|
||||||
self._session.remove_torrent(handle._handle, 1 if remove_files else 0)
|
self._session.remove_torrent(handle._handle, 1 if remove_files else 0)
|
||||||
self._handles.pop(btih)
|
self._handles.pop(btih)
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,9 @@ class FileCommands(CommandTestCase):
|
||||||
self.assertIn(new_btih, self.client_session._handles)
|
self.assertIn(new_btih, self.client_session._handles)
|
||||||
self.assertNotIn(btih, self.client_session._handles)
|
self.assertNotIn(btih, self.client_session._handles)
|
||||||
self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1)
|
self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1)
|
||||||
|
await self.daemon.jsonrpc_file_delete(delete_all=True)
|
||||||
|
self.assertItemCount(await self.daemon.jsonrpc_file_list(), 0)
|
||||||
|
self.assertNotIn(new_btih, self.client_session._handles)
|
||||||
|
|
||||||
async def create_streams_in_range(self, *args, **kwargs):
|
async def create_streams_in_range(self, *args, **kwargs):
|
||||||
self.stream_claim_ids = []
|
self.stream_claim_ids = []
|
||||||
|
|
Loading…
Reference in a new issue