From d4d1d87680dd836eb60c2e004f992b6ec79ef4e7 Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Fri, 11 Oct 2019 20:52:51 +0200 Subject: [PATCH] Revert changes to cli, apply suggestions --- lbry/lbry/extras/daemon/Daemon.py | 15 ++++++--------- lbry/lbry/testcase.py | 6 +++--- lbry/tests/integration/test_file_commands.py | 4 ++-- lbry/tests/unit/stream/test_stream_descriptor.py | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lbry/lbry/extras/daemon/Daemon.py b/lbry/lbry/extras/daemon/Daemon.py index 8a1de8b85..bd32db9fe 100644 --- a/lbry/lbry/extras/daemon/Daemon.py +++ b/lbry/lbry/extras/daemon/Daemon.py @@ -2810,7 +2810,7 @@ class Daemon(metaclass=JSONRPCServerType): @requires(WALLET_COMPONENT, STREAM_MANAGER_COMPONENT, BLOB_COMPONENT, DATABASE_COMPONENT) async def jsonrpc_stream_update( - self, claim_id, bid=None, file_path=None, file_name=None, + self, claim_id, bid=None, file_path=None, channel_id=None, channel_name=None, channel_account_id=None, clear_channel=False, account_id=None, wallet_id=None, claim_address=None, funding_account_ids=None, preview=False, blocking=False, replace=False, **kwargs): @@ -2979,7 +2979,7 @@ class Daemon(metaclass=JSONRPCServerType): claim.stream.update(file_path=file_path, **kwargs) else: claim = Claim.from_bytes(old_txo.claim.to_bytes()) - claim.stream.update(file_path=file_path, file_name=file_name, **kwargs) + claim.stream.update(file_path=file_path, **kwargs) tx = await Transaction.claim_update( old_txo, claim, amount, claim_address, funding_accounts, funding_accounts[0], channel ) @@ -2988,13 +2988,10 @@ class Daemon(metaclass=JSONRPCServerType): stream_hash = None if not preview: old_stream_hash = await self.storage.get_stream_hash_for_sd_hash(old_txo.claim.stream.source.sd_hash) - old_stream = self.stream_manager.get_stream_by_stream_hash(old_stream_hash) - if not file_path and file_name and old_stream: - old_path, _ = os.path.split(old_stream.full_path) - file_path = os.path.join(old_path, file_name) - if file_path: - if old_stream: - await self.stream_manager.delete_stream(old_stream, delete_file=False) + if file_path is not None: + if old_stream_hash: + stream_to_delete = self.stream_manager.get_stream_by_stream_hash(old_stream_hash) + await self.stream_manager.delete_stream(stream_to_delete, delete_file=False) file_stream = await self.stream_manager.create_stream(file_path) new_txo.claim.stream.source.sd_hash = file_stream.sd_hash new_txo.script.generate() diff --git a/lbry/lbry/testcase.py b/lbry/lbry/testcase.py index 8c2c397d2..6f92f90af 100644 --- a/lbry/lbry/testcase.py +++ b/lbry/lbry/testcase.py @@ -197,9 +197,9 @@ class CommandTestCase(IntegrationTestCase): """ Synchronous version of `out` method. """ return json.loads(jsonrpc_dumps_pretty(value, ledger=self.ledger))['result'] - def create_tempfile(self, data=None, prefix=None, suffix=None, dir=None): - dir = dir or self.daemon.conf.download_dir - file = tempfile.NamedTemporaryFile(prefix=prefix, suffix=suffix, dir=dir) + def create_tempfile(self, data=None, prefix=None, suffix=None, dir_path=None): + dir_path = dir_path or self.daemon.conf.download_dir + file = tempfile.NamedTemporaryFile(prefix=prefix, suffix=suffix, dir=dir_path) file.write(data) file.flush() diff --git a/lbry/tests/integration/test_file_commands.py b/lbry/tests/integration/test_file_commands.py index 2e05b6d4b..a60270bbd 100644 --- a/lbry/tests/integration/test_file_commands.py +++ b/lbry/tests/integration/test_file_commands.py @@ -103,8 +103,8 @@ class FileCommands(CommandTestCase): # Update the stream and assert the file name is not sanitized, but the suggested file name is prefix, suffix = 'derpyderp?', '.ext.' san_prefix, san_suffix = 'derpyderp', '.ext' - new_file_name = os.path.basename(self.create_tempfile(data=b'amazing content', prefix=prefix, suffix=suffix)) - tx = await self.stream_update(claim_id, file_name=new_file_name) + new_file_path = self.create_tempfile(data=b'amazing content', prefix=prefix, suffix=suffix) + tx = await self.stream_update(claim_id, file_path=new_file_path) full_path = (await self.daemon.jsonrpc_get('lbry://' + claim_name, save_file=True)).full_path updated_stream = self.daemon.jsonrpc_file_list()[0] diff --git a/lbry/tests/unit/stream/test_stream_descriptor.py b/lbry/tests/unit/stream/test_stream_descriptor.py index d60618201..62b0af5a5 100644 --- a/lbry/tests/unit/stream/test_stream_descriptor.py +++ b/lbry/tests/unit/stream/test_stream_descriptor.py @@ -78,7 +78,7 @@ class TestStreamDescriptor(AsyncioTestCase): self.sd_dict['blobs'][-2]['length'] = 0 await self._test_invalid_sd() - async def test_sanitize_file_name(self): + def test_sanitize_file_name(self): test_cases = [' t/-?t|.g.ext ', 'end_dot .', '.file\0\0', 'test n\16ame.ext', 'COM8', 'LPT2', ''] expected = ['t-t.g.ext', 'end_dot', '.file', 'test name.ext', '', '', ''] actual = [sanitize_file_name(tc) for tc in test_cases]