fix deleting incomplete downloads upon stop

fix deleting previous streams (not assembled/published files) for a claim being updated
This commit is contained in:
Jack Robison 2019-02-05 15:26:14 -05:00
parent 073ffdd049
commit 7c8ad0fe30
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
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: 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 i = 0
while os.path.isfile(os.path.join(download_directory, file_name)): while os.path.isfile(os.path.join(download_directory, file_name)):
i += 1 i += 1

View file

@ -170,6 +170,10 @@ class ManagedStream:
def stop_download(self): def stop_download(self):
if self.downloader: if self.downloader:
self.downloader.stop() 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: if not self.finished:
self.update_status(self.STATUS_STOPPED) self.update_status(self.STATUS_STOPPED)

View file

@ -194,10 +194,6 @@ class StreamManager:
return stream return stream
async def delete_stream(self, stream: ManagedStream, delete_file: typing.Optional[bool] = False): 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() stream.stop_download()
self.streams.remove(stream) self.streams.remove(stream)
await self.storage.delete_stream(stream.descriptor) await self.storage.delete_stream(stream.descriptor)