Skip to content

Commit

Permalink
apps: Fix reading AppStream metadata config
Browse files Browse the repository at this point in the history
Commit 7bbf916 introduced a major bug: If the OS in os-release was
not found in the iteration, get_config() would return the whole map
instead of the default value. That crashed the page with
`TypeError: names.forEach is not a function`.

This is awkward to do correctly with .find(), especially due to
modifying `val` as a side effect; iterate over `os_list` the good old
`for` way instead.

This was hidden by the test's manifest override leaving
`appstream_config_packages` intact, so it was always taken from the real
underlying OS. Override it as well.

Cherry-picked from 0eeb475
  • Loading branch information
martinpitt committed Dec 12, 2023
1 parent e85b0e5 commit 957283a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
14 changes: 6 additions & 8 deletions pkg/apps/application-list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,13 @@ export const ApplicationList = ({ metainfo_db, appProgress, appProgressTitle, ac
const os_list = [os_release.ID || "", ...(os_release.ID_LIKE || "").split(/\s+/)];

if (cockpit.manifests.apps && cockpit.manifests.apps.config) {
let val = cockpit.manifests.apps.config[name];
const val = cockpit.manifests.apps.config[name];
if (typeof val === 'object' && val !== null && !Array.isArray(val)) {
os_list.find(c => {
if (val[c]) {
val = val[c];
return true;
}
return false;
});
for (const os of os_list) {
if (val[os])
return val[os];
}
return def;
}
return val !== undefined ? val : def;
} else {
Expand Down
3 changes: 2 additions & 1 deletion test/verify/check-apps
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ class TestApps(packagelib.PackageCase):
# use a fake distro map
self.write_file("/etc/cockpit/apps.override.json",
'{ "config": { "appstream_data_packages":'
' {"testy": ["appstream-data-test"], "otheros": ["nosuchpackage"]}'
' {"testy": ["appstream-data-test"], "otheros": ["nosuchpackage"]},'
' "appstream_config_packages": []'
' }}')

self.createAppStreamPackage("app-1", "1.0", "1")
Expand Down

0 comments on commit 957283a

Please sign in to comment.