From 15376c19be4e4cd62f4070073d265da44bd6bcf4 Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Wed, 9 Oct 2019 19:32:52 +0200 Subject: [PATCH] Apply suggestions --- lbry/lbry/stream/descriptor.py | 7 ++++--- lbry/lbry/stream/managed_stream.py | 4 ++-- lbry/tests/integration/test_file_commands.py | 11 ++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lbry/lbry/stream/descriptor.py b/lbry/lbry/stream/descriptor.py index ca22a1f60..b965253cb 100644 --- a/lbry/lbry/stream/descriptor.py +++ b/lbry/lbry/stream/descriptor.py @@ -89,7 +89,7 @@ class StreamDescriptor: self.blob_dir = blob_dir self.stream_name = stream_name self.key = key - self.suggested_file_name = sanitize_file_name(suggested_file_name) + self.suggested_file_name = suggested_file_name self.blobs = blobs self.stream_hash = stream_hash or self.get_stream_hash() self.sd_hash = sd_hash @@ -251,9 +251,10 @@ class StreamDescriptor: blobs.append(blob_info) blobs.append( BlobInfo(len(blobs), 0, binascii.hexlify(next(iv_generator)).decode())) # add the stream terminator + file_name = os.path.basename(file_path) + suggested_file_name = sanitize_file_name(file_name) descriptor = cls( - loop, blob_dir, os.path.basename(file_path), binascii.hexlify(key).decode(), os.path.basename(file_path), - blobs + loop, blob_dir, file_name, binascii.hexlify(key).decode(), suggested_file_name, blobs ) sd_blob = await descriptor.make_sd_blob(old_sort=old_sort, blob_completed_callback=blob_completed_callback) descriptor.sd_hash = sd_blob.blob_hash diff --git a/lbry/lbry/stream/managed_stream.py b/lbry/lbry/stream/managed_stream.py index 16a56ff56..3b2da43e1 100644 --- a/lbry/lbry/stream/managed_stream.py +++ b/lbry/lbry/stream/managed_stream.py @@ -8,7 +8,7 @@ from lbry.utils import generate_id from lbry.error import DownloadSDTimeout from lbry.schema.mime_types import guess_media_type from lbry.stream.downloader import StreamDownloader -from lbry.stream.descriptor import StreamDescriptor +from lbry.stream.descriptor import StreamDescriptor, sanitize_file_name from lbry.stream.reflector.client import StreamReflectorClient from lbry.extras.daemon.storage import StoredStreamClaim from lbry.blob import MAX_BLOB_SIZE @@ -386,7 +386,7 @@ class ManagedStream: os.mkdir(self.download_directory) self._file_name = await get_next_available_file_name( self.loop, self.download_directory, - file_name or self.file_name + file_name or self._file_name or sanitize_file_name(self.descriptor.suggested_file_name) ) await self.blob_manager.storage.change_file_download_dir_and_file_name( self.stream_hash, self.download_directory, self.file_name diff --git a/lbry/tests/integration/test_file_commands.py b/lbry/tests/integration/test_file_commands.py index be1a0c074..6881bce69 100644 --- a/lbry/tests/integration/test_file_commands.py +++ b/lbry/tests/integration/test_file_commands.py @@ -51,11 +51,11 @@ class FileCommands(CommandTestCase): suffix = '.ext.' san_prefix = 'antz m' san_suffix = '.ext' - claim = await self.stream_create('foo', '0.01', prefix=prefix, suffix=suffix) + tx = await self.stream_create('foo', '0.01', prefix=prefix, suffix=suffix) stream = self.daemon.jsonrpc_file_list()[0] - # Check that file list and source contains the local unsanitized name, but suggested name is sanitized - source_file_name = claim['outputs'][0]['value']['source']['name'] + # Assert that file list and source contains the local unsanitized name, but suggested name is sanitized + source_file_name = tx['outputs'][0]['value']['source']['name'] file_list_name = stream.file_name suggested_file_name = stream.descriptor.suggested_file_name self.assertTrue(source_file_name.startswith(prefix)) @@ -64,15 +64,16 @@ class FileCommands(CommandTestCase): self.assertTrue(suggested_file_name.startswith(san_prefix)) self.assertTrue(suggested_file_name.endswith(san_suffix)) - # Delete the file, re-download and check that the file name is sanitized + # Delete the file, re-download and assert that the file name is sanitized self.assertTrue(await self.daemon.jsonrpc_file_delete(claim_name='foo')) + self.assertEqual(len(self.daemon.jsonrpc_file_list()), 0) full_path = (await self.daemon.jsonrpc_get('lbry://foo', save_file=True)).full_path file_name = os.path.basename(full_path) self.assertTrue(os.path.isfile(full_path)) self.assertTrue(file_name.startswith(san_prefix)) self.assertTrue(file_name.endswith(san_suffix)) - # Check that the downloaded file name is not sanitized when user provides custom file name + # Assert that the downloaded file name is not sanitized when user provides custom file name self.assertTrue(await self.daemon.jsonrpc_file_delete(claim_name='foo')) file_name = 'my