From 52175e7fa8c3ae8523bdc9f3ddcfe161781caaf8 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Sat, 11 Jan 2025 14:43:45 +0000 Subject: [PATCH] Match selected Endless Key content collections correctly EIB_ENDLESSKEY_COLLECTIONS is a whitespace (typically space or newline)-separated list of collection names. These are matched against collection filenames to determine what to fetch. We have collection files named `extras-preload-0001.json` and `spanish-extras-preload-0001.json`. The intention is that if `[endlesskey] collections` contains `spanish-extras-preload` but not `extras-preload`, only the latter will be imported, not the former. However, the logic that matched filenames against the configured array did not consider the case when one collection name is a substring of another. It would incorrectly match `extras-preload-0001.json` against `spanish-extras-preload` because the latter contains `extras-preload` as a substring. Make the check more precise by checking that the desired collection name is present in EIB_ENDLESSKEY_COLLECTIONS, surrounded by whitespace. Surround EIB_ENDLESSKEY_COLLECTIONS itself with whitespace to make this check work for the first or last collection in the list. (The root cause of this bug is that shell scripts are not a suitable language for non-trivial logic. I tried to use Bash arrays but apparently Bash does not have a "contains" operator for arrays.) https://phabricator.endlessm.com/T35668#1004203 --- hooks/image/53-ek-content-preload | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/image/53-ek-content-preload b/hooks/image/53-ek-content-preload index fc15b1fc..495d15d9 100644 --- a/hooks/image/53-ek-content-preload +++ b/hooks/image/53-ek-content-preload @@ -17,8 +17,8 @@ all_collection_files="${OSTREE_VAR}"/lib/flatpak/app/org.endlessos.Key/current/a for collection_file in ${all_collection_files}; do # Check if the file basename stripped off of -0001.json is part of the list # of collections to be installed. - bn=$(basename ${collection_file}) - if [[ "${EIB_ENDLESSKEY_COLLECTIONS}" =~ .*"${bn%-????.json}".* ]] ; then + bn=$(basename "${collection_file%-????.json}") + if [[ " ${EIB_ENDLESSKEY_COLLECTIONS} " =~ [[:space:]]${bn}[[:space:]] ]] ; then selected_collection_files+=("${collection_file}") jq -r '.channels[].id' "${collection_file}" >> "${channels_file}" fi