index: error if duplicate package files are in repo

Looks like the ~index-v2 work removed this error case, and the old bash
integration test case failed to catch it.  This reestablishes this error.

@mindston's refactoring of the old bash test suite caught this issue, e.g.
!1587
This commit is contained in:
Hans-Christoph Steiner 2025-02-12 18:25:33 +01:00
parent 6df9d0ecba
commit f7dc89e9ba

View file

@ -2668,8 +2668,20 @@ def main():
appid_has_apks = set() appid_has_apks = set()
appid_has_repo_files = set() appid_has_repo_files = set()
sha256_has_files = collections.defaultdict(list)
errors = 0
remove_apks = [] remove_apks = []
for apk in apks: for apk in apks:
sha256 = apk['hash']
if sha256 in sha256_has_files:
errors += 1
for path2 in sha256_has_files[sha256]:
logging.error(
_('{path1} is a duplicate of {path2}, remove one!').format(
path1=apk["apkName"], path2=path2
)
)
sha256_has_files[sha256].append(apk['apkName'])
to_remove = get_apks_without_allowed_signatures(apps.get(apk['packageName']), apk) to_remove = get_apks_without_allowed_signatures(apps.get(apk['packageName']), apk)
if to_remove: if to_remove:
remove_apks.append(apk) remove_apks.append(apk)
@ -2712,14 +2724,17 @@ def main():
for apk in remove_apks: for apk in remove_apks:
apks.remove(apk) apks.remove(apk)
mismatch_errors = ''
for appid in appid_has_apks: for appid in appid_has_apks:
if appid in appid_has_repo_files: if appid in appid_has_repo_files:
appid_files = ', '.join(glob.glob(os.path.join('repo', appid + '_[0-9]*.*'))) appid_files = ', '.join(glob.glob(os.path.join('repo', appid + '_[0-9]*.*')))
mismatch_errors += (_('{appid} has both APKs and files: {files}') errors += 1
.format(appid=appid, files=appid_files)) + '\n' logging.error(
if mismatch_errors: _('{appid} has both APKs and files: {files}').format(
raise FDroidException(mismatch_errors) appid=appid, files=appid_files
)
)
if errors:
sys.exit(errors)
# Scan the archive repo for apks as well # Scan the archive repo for apks as well
if len(repodirs) > 1: if len(repodirs) > 1: