Apply suggestions

This commit is contained in:
Miroslav Kovar 2019-10-09 19:32:52 +02:00 committed by Lex Berezhny
parent f92b610a03
commit 15376c19be
3 changed files with 12 additions and 10 deletions

View file

@ -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

View file

@ -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

View file

@ -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 <u?|*m.name'
full_path = (await self.daemon.jsonrpc_get('lbry://foo', file_name=file_name, save_file=True)).full_path