From 45c9fb967a602349ba697c106e28e2ca2ae1ebf9 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 28 May 2018 15:12:45 +0200 Subject: [PATCH] extensions: Respect versions (as well as version) when finding related refs This allows one extension point to match multiple versions of an extension. In particular, this is useful for OpenGL so that we can match the version matching the current runtime, as well as the "magic" 1.4 version for nvidia. Closes: #1722 Approved by: alexlarsson --- common/flatpak-dir.c | 54 ++++++++++++++++++++++++++-------------- tests/test-extensions.sh | 13 ++++++++++ 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index f4aed7ac..e2ce5c69 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -10928,6 +10928,9 @@ flatpak_dir_find_remote_related (FlatpakDir *self, g_autofree char *extension = NULL; g_autofree char *version = g_key_file_get_string (metakey, groups[i], FLATPAK_METADATA_KEY_VERSION, NULL); + g_auto(GStrv) versions = g_key_file_get_string_list (metakey, groups[i], + FLATPAK_METADATA_KEY_VERSIONS, + NULL, NULL); gboolean subdirectories = g_key_file_get_boolean (metakey, groups[i], FLATPAK_METADATA_KEY_SUBDIRECTORIES, NULL); gboolean no_autodownload = g_key_file_get_boolean (metakey, groups[i], @@ -10939,17 +10942,25 @@ flatpak_dir_find_remote_related (FlatpakDir *self, gboolean locale_subset = g_key_file_get_boolean (metakey, groups[i], FLATPAK_METADATA_KEY_LOCALE_SUBSET, NULL); g_autofree char *extension_collection_id = NULL; - const char *branch; + const char *default_branches[] = { NULL, NULL}; + const char **branches; g_autofree char *extension_ref = NULL; g_autofree char *checksum = NULL; + int branch_i; /* Parse actual extension name */ flatpak_parse_extension_with_tag (tagged_extension, &extension, NULL); - if (version) - branch = version; + if (versions) + branches = (const char **)versions; else - branch = parts[3]; + { + if (version) + default_branches[0] = version; + else + default_branches[0] = parts[3]; + branches = default_branches; + } #ifdef FLATPAK_ENABLE_P2P extension_collection_id = g_key_file_get_string (metakey, groups[i], @@ -10970,24 +10981,29 @@ flatpak_dir_find_remote_related (FlatpakDir *self, g_clear_pointer (&extension_collection_id, g_free); extension_collection_id = g_strdup (state->collection_id); - extension_ref = g_build_filename ("runtime", extension, parts[2], branch, NULL); + for (branch_i = 0; branches[branch_i] != NULL; branch_i++) + { + const char *branch = branches[branch_i]; - if (flatpak_remote_state_lookup_ref (state, extension_ref, &checksum, NULL, NULL)) - { - add_related (self, related, extension, extension_collection_id, extension_ref, checksum, - no_autodownload, download_if, autodelete, locale_subset); - } - else if (subdirectories) - { - g_auto(GStrv) refs = flatpak_remote_state_match_subrefs (state, extension_ref); - int j; - for (j = 0; refs[j] != NULL; j++) + extension_ref = g_build_filename ("runtime", extension, parts[2], branch, NULL); + + if (flatpak_remote_state_lookup_ref (state, extension_ref, &checksum, NULL, NULL)) { - g_autofree char *subref_checksum = NULL; + add_related (self, related, extension, extension_collection_id, extension_ref, checksum, + no_autodownload, download_if, autodelete, locale_subset); + } + else if (subdirectories) + { + g_auto(GStrv) refs = flatpak_remote_state_match_subrefs (state, extension_ref); + int j; + for (j = 0; refs[j] != NULL; j++) + { + g_autofree char *subref_checksum = NULL; - if (flatpak_remote_state_lookup_ref (state, refs[j], &subref_checksum, NULL, NULL)) - add_related (self, related, extension, extension_collection_id, refs[j], subref_checksum, - no_autodownload, download_if, autodelete, locale_subset); + if (flatpak_remote_state_lookup_ref (state, refs[j], &subref_checksum, NULL, NULL)) + add_related (self, related, extension, extension_collection_id, refs[j], subref_checksum, + no_autodownload, download_if, autodelete, locale_subset); + } } } } diff --git a/tests/test-extensions.sh b/tests/test-extensions.sh index 00335cd8..2da7ab0c 100755 --- a/tests/test-extensions.sh +++ b/tests/test-extensions.sh @@ -57,6 +57,7 @@ add_extensions () { mkdir -p $DIR/files/foo/none mkdir -p $DIR/files/foo/dir mkdir -p $DIR/files/foo/dir2 + mkdir -p $DIR/files/foo/multiversion cat >> $DIR/metadata <