refactor: remove the support of the index only mode when syncing to the local filesystem

This commit is contained in:
proletarius101 2024-01-20 17:01:36 +08:00
parent 574c5aec17
commit 7064160fbf
No known key found for this signature in database
2 changed files with 11 additions and 86 deletions

View File

@ -391,19 +391,14 @@ 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(options,
os.path.join(local_copy_dir, repo_section).rstrip('/') + '/',
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(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(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')):
@ -420,14 +415,10 @@ def update_localcopy(repo_section, local_copy_dir):
"""
if options.index_only:
rsyncargs = ['--include', "*/"] + _get_index_includes(repo_section) + ['--exclude', '*']
common.local_rsync(options,
repo_section,
local_copy_dir,
args=rsyncargs)
else:
# local_copy_dir is guaranteed to have a trailing slash in main() below
common.local_rsync(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(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')):

View File

@ -507,72 +507,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'
)