From 494d811846f8c66cc92a5688c2e9290a4b7bf2ab Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 22 May 2025 19:54:07 +0200 Subject: [PATCH] update: If cateogories.yml only has icon:, then add name: E.g. if _categories.yml_ is like: ```yaml Time: icon: time.png ``` --- fdroidserver/index.py | 4 +++- tests/test_update.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/fdroidserver/index.py b/fdroidserver/index.py index b65aa2b1..86394d7c 100644 --- a/fdroidserver/index.py +++ b/fdroidserver/index.py @@ -775,7 +775,9 @@ def make_v2(apps, packages, repodir, repodict, requestsdict, signer_fingerprints # include definitions for "auto-defined" categories, e.g. just used in app metadata for category in sorted(categories_used_by_apps): if category not in output['repo'][CATEGORIES_CONFIG_NAME]: - output['repo'][CATEGORIES_CONFIG_NAME][category] = {"name": {DEFAULT_LOCALE: category}} + output['repo'][CATEGORIES_CONFIG_NAME][category] = dict() + if 'name' not in output['repo'][CATEGORIES_CONFIG_NAME][category]: + output['repo'][CATEGORIES_CONFIG_NAME][category]['name'] = {DEFAULT_LOCALE: category} # do not include defined categories if no apps use them for category in list(output['repo'].get(CATEGORIES_CONFIG_NAME, list())): if category not in categories_used_by_apps: diff --git a/tests/test_update.py b/tests/test_update.py index 3d047d75..dbfbdef1 100755 --- a/tests/test_update.py +++ b/tests/test_update.py @@ -1913,6 +1913,41 @@ class UpdateTest(unittest.TestCase): index['repo'][CATEGORIES_CONFIG_NAME], ) + def test_categories_with_only_icon_defined(self): + """If cateogories.yml only includes the icon, the name should be added.""" + os.chdir(self.testdir) + os.mkdir('config') + os.mkdir('metadata') + os.mkdir('repo') + fdroidserver.common.write_config_file( + 'repo_pubkey: ffffffffffffffffffffffffffffffffffffffff\n' + ) + testvalue = 'Time' + Path('config/time.png').write_text('placeholder') + Path('config/categories.yml').write_text(testvalue + ': {icon: time.png}') + + testapk = os.path.join('repo', 'com.politedroid_6.apk') + shutil.copy(basedir / testapk, testapk) + Path('metadata/com.politedroid.yml').write_text(f'Categories: [{testvalue}]') + + with mock.patch('sys.argv', ['fdroid update', '--delete-unknown', '--nosign']): + fdroidserver.update.main() + with open('repo/index-v2.json') as fp: + index = json.load(fp) + self.assertEqual( + { + 'icon': { + 'en-US': { + 'name': '/icons/time.png', + 'sha256': '4097889236a2af26c293033feb964c4cf118c0224e0d063fec0a89e9d0569ef2', + 'size': 11, + } + }, + 'name': {'en-US': testvalue}, + }, + index['repo'][CATEGORIES_CONFIG_NAME][testvalue], + ) + def test_auto_defined_categories_two_apps(self): """Repos that don't define categories in config/ should use auto-generated.""" os.chdir(self.testdir)