Merge pull request #1865 from lbryio/fix-delete-previous-stream

Fix deleting incomplete downloads when they are stopped
This commit is contained in:
Jack Robison 2019-02-05 15:43:55 -05:00 committed by GitHub
commit 82b53e108c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View file

@ -15,7 +15,7 @@ log = logging.getLogger(__name__)
def _get_next_available_file_name(download_directory: str, file_name: str) -> str:
base_name, ext = os.path.splitext(file_name)
base_name, ext = os.path.splitext(os.path.basename(file_name))
i = 0
while os.path.isfile(os.path.join(download_directory, file_name)):
i += 1

View file

@ -170,6 +170,10 @@ class ManagedStream:
def stop_download(self):
if self.downloader:
self.downloader.stop()
if not self.downloader.stream_finished_event.is_set() and self.downloader.wrote_bytes_event.is_set():
path = os.path.join(self.download_directory, self.file_name)
if os.path.isfile(path):
os.remove(path)
if not self.finished:
self.update_status(self.STATUS_STOPPED)

View file

@ -194,10 +194,6 @@ class StreamManager:
return stream
async def delete_stream(self, stream: ManagedStream, delete_file: typing.Optional[bool] = False):
stream_finished = False if not stream.finished and stream.downloader\
else (stream.downloader and stream.downloader.stream_finished_event.is_set())
if not stream_finished:
delete_file = True
stream.stop_download()
self.streams.remove(stream)
await self.storage.delete_stream(stream.descriptor)