index: fail if user sets mirrors:isPrimary wrong

Really, this is not meant to be set by the user in the config.  But if they
add something harmless that'll be ignored anyway, it seems that throwing an
error is too much.  So only throw the error if it is set wrongly.
This commit is contained in:
Hans-Christoph Steiner 2025-03-19 17:39:45 +01:00
parent 8e39f82eb9
commit 20569217d9
2 changed files with 24 additions and 0 deletions

View file

@ -1516,6 +1516,7 @@ def add_mirrors_to_repodict(repo_section, repodict):
repodict['mirrors'] = []
canonical_url = repodict['address']
found_primary = False
errors = 0
for mirror in mirrors:
if canonical_url == mirror['url']:
found_primary = True
@ -1524,9 +1525,19 @@ def add_mirrors_to_repodict(repo_section, repodict):
for k in sorted(mirror.keys()):
sortedmirror[k] = mirror[k]
repodict['mirrors'].insert(0, sortedmirror)
elif mirror.get('isPrimary'):
errors += 1
logging.error(
_('Mirror config for {url} contains "isPrimary" key!').format(
url=mirror['url']
)
)
else:
repodict['mirrors'].append(mirror)
if errors:
raise FDroidException(_('"isPrimary" key should not be added to mirrors!'))
if repodict['mirrors'] and not found_primary:
repodict['mirrors'].insert(0, {'isPrimary': True, 'url': repodict['address']})