From c7574037a9f752e65d42ef03c61ff6b50927c32c Mon Sep 17 00:00:00 2001 From: proletarius101 Date: Sat, 20 Jan 2024 17:01:36 +0800 Subject: [PATCH] refactor: remove the support of the index only mode when syncing to the local filesystem --- fdroidserver/deploy.py | 35 +++++++++------------- tests/deploy.TestCase | 66 ------------------------------------------ 2 files changed, 13 insertions(+), 88 deletions(-) diff --git a/fdroidserver/deploy.py b/fdroidserver/deploy.py index ae45e676..2046bc2d 100644 --- a/fdroidserver/deploy.py +++ b/fdroidserver/deploy.py @@ -561,21 +561,16 @@ def sync_from_localcopy(repo_section, local_copy_dir): push to all the servers that are configured. """ - logging.info('Syncing from local_copy_dir to this repo.') if options.index_only: - rsyncargs = ['--include', "*/"] + _get_index_includes(repo_section) + ['--exclude', '*'] - common.local_rsync(common.get_options(), - _get_index_includes(local_copy_dir), - repo_section.rstrip('/') + '/', - args=rsyncargs) - else: - # trailing slashes have a meaning in rsync which is not needed here, so - # make sure both paths have exactly one trailing slash - common.local_rsync( - common.get_options(), - os.path.join(local_copy_dir, repo_section).rstrip('/') + '/', - repo_section.rstrip('/') + '/', - ) + raise FDroidException(_('The index only mode cannot be used when syncing to the local copy filesystem')) + + # trailing slashes have a meaning in rsync which is not needed here, so + # make sure both paths have exactly one trailing slash + common.local_rsync( + common.get_options(), + os.path.join(local_copy_dir, repo_section).rstrip('/') + '/', + repo_section.rstrip('/') + '/', + ) offline_copy = os.path.join(local_copy_dir, BINARY_TRANSPARENCY_DIR) if os.path.exists(os.path.join(offline_copy, '.git')): @@ -592,14 +587,10 @@ def update_localcopy(repo_section, local_copy_dir): """ if options.index_only: - rsyncargs = ['--include', "*/"] + _get_index_includes(repo_section) + ['--exclude', '*'] - common.local_rsync(common.get_options(), - _get_index_includes(repo_section), - local_copy_dir, - args=rsyncargs) - else: - # local_copy_dir is guaranteed to have a trailing slash in main() below - common.local_rsync(common.get_options(), repo_section, local_copy_dir) + raise FDroidException(_('The index only mode cannot be used when syncing to the local copy filesystem')) + + # local_copy_dir is guaranteed to have a trailing slash in main() below + common.local_rsync(common.get_options(), repo_section, local_copy_dir) offline_copy = os.path.join(os.getcwd(), BINARY_TRANSPARENCY_DIR) if os.path.isdir(os.path.join(offline_copy, '.git')): diff --git a/tests/deploy.TestCase b/tests/deploy.TestCase index ceafc4ca..ddd8aedd 100755 --- a/tests/deploy.TestCase +++ b/tests/deploy.TestCase @@ -561,72 +561,6 @@ class DeployTest(unittest.TestCase): fdroidserver.deploy.update_serverwebroot({'url': url}, repo_section) self.assertEqual(call_iteration, 1, 'expected 1 invocations of subprocess.call') - def test_update_localcopy_in_index_only_mode(self): - # setup parameters for this test run - fdroidserver.deploy.options.no_chcksum = False - fdroidserver.deploy.options.verbose = True - fdroidserver.deploy.options.quiet = False - fdroidserver.deploy.options.identity_file = None - fdroidserver.deploy.options.index_only = True - repo_section = 'repo' - - # setup function for asserting subprocess.call invocations - call_iteration = 0 - - with tempfile.TemporaryDirectory() as local_copy_dir: - - def update_localcopy_call(cmd): - nonlocal call_iteration - if call_iteration == 0: - self.assertListEqual( - cmd, - [ - 'rsync', - '--recursive', - '--safe-links', - '--times', - '--perms', - '--one-file-system', - '--delete', - '--chmod=Da+rx,Fa-x,a+r,u+w', - '--verbose', - '--include', - "*/", - '--include', - 'repo/entry.jar', - '--include', - 'repo/entry.json', - '--include', - 'repo/entry.json.asc', - '--include', - 'repo/index-v1.jar', - '--include', - 'repo/index-v1.json', - '--include', - 'repo/index-v1.json.asc', - '--include', - 'repo/index-v2.json', - '--include', - 'repo/index-v2.json.asc', - '--include', - 'repo/index.jar', - '--include', - 'repo/index.xml', - '--exclude', - "*", - 'repo', - local_copy_dir, - ], - ) - else: - self.fail('unexpected subprocess.call invocation') - call_iteration += 1 - return 0 - - with mock.patch('subprocess.call', side_effect=update_localcopy_call): - fdroidserver.deploy.update_localcopy(repo_section, local_copy_dir) - self.assertEqual(call_iteration, 1, 'expected 1 invocations of subprocess.call') - @unittest.skipIf( not os.getenv('VIRUSTOTAL_API_KEY'), 'VIRUSTOTAL_API_KEY is not set' )