From 05e2afa8ced7958fa7829612bd7dd5b80dd48872 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 11 Oct 2017 14:21:41 +0200 Subject: [PATCH] Fix up subpath handling Whenever we add a add a local dependency we add both the languages based on the current locale, and (in case of an update) whatever was installed before. We also properly merge this with any normally specified (non-dependency) update (typically happens e.g. when just doing a "flatpak update", which adds .Locale updates both as dependencies and regular updates). This means you can just configure a new language and then flatpak update will pull everything with those languages. Closes: #1098 Approved by: alexlarsson --- app/flatpak-transaction.c | 18 +++--------------- common/flatpak-dir.c | 38 +++++--------------------------------- 2 files changed, 8 insertions(+), 48 deletions(-) diff --git a/app/flatpak-transaction.c b/app/flatpak-transaction.c index c32d39ff..208a3235 100644 --- a/app/flatpak-transaction.c +++ b/app/flatpak-transaction.c @@ -40,6 +40,7 @@ typedef enum { struct FlatpakTransactionOp { char *remote; char *ref; + /* NULL means unspecified (normally keep whatever was there before), [] means force everything */ char **subpaths; char *commit; GFile *bundle; @@ -267,13 +268,8 @@ flatpak_transaction_add_op (FlatpakTransaction *self, op = g_hash_table_lookup (self->refs, ref); if (op != NULL) { - /* Only override subpaths if already specified, - we always want the un-subpathed to win if specified. */ - if (op->subpaths != NULL && op->subpaths[0] != NULL && subpaths != NULL) - { - g_strfreev (op->subpaths); - op->subpaths = g_strdupv ((char **)subpaths); - } + g_auto(GStrv) old_subpaths = op->subpaths; + op->subpaths = flatpak_subpaths_merge (old_subpaths, (char **)subpaths); return op; } @@ -676,14 +672,6 @@ flatpak_transaction_run (FlatpakTransaction *self, if (dir_ref_is_installed (self->dir, op->ref, NULL, &deploy_data)) { - g_autofree const char **current_subpaths = NULL; - - /* When we update a dependency, we always inherit the subpaths - rather than use the default. */ - g_strfreev (op->subpaths); - current_subpaths = flatpak_deploy_data_get_subpaths (deploy_data); - op->subpaths = g_strdupv ((char **)current_subpaths); - /* Don't use the remote from related ref on update, always use the current remote. */ g_free (op->remote); diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index c1c1e87c..46a80c70 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -9852,21 +9852,6 @@ flatpak_related_free (FlatpakRelated *self) g_free (self); } -static gboolean -string_in_array (GPtrArray *array, - const char *str) -{ - int i; - - for (i = 0; i < array->len; i++) - { - if (strcmp (g_ptr_array_index (array, i), str) == 0) - return TRUE; - } - - return FALSE; -} - static void add_related (FlatpakDir *self, GPtrArray *related, @@ -9881,8 +9866,8 @@ add_related (FlatpakDir *self, { g_autoptr(GVariant) deploy_data = NULL; g_autofree const char **old_subpaths = NULL; - g_autoptr(GPtrArray) subpaths = g_ptr_array_new_with_free_func (g_free); - int i; + g_auto(GStrv) extra_subpaths = NULL; + g_auto(GStrv) subpaths = NULL; FlatpakRelated *rel; gboolean download; gboolean delete = autodelete; @@ -9926,34 +9911,21 @@ add_related (FlatpakDir *self, if (g_str_has_suffix (extension, ".Locale")) locale_subset = TRUE; - if (old_subpaths) - { - for (i = 0; old_subpaths[i] != NULL; i++) - g_ptr_array_add (subpaths, g_strdup (old_subpaths[i])); - } - if (locale_subset) { - g_autofree char ** current_subpaths = flatpak_dir_get_locale_subpaths (self); - for (i = 0; current_subpaths[i] != NULL; i++) - { - g_autofree char *subpath = current_subpaths[i]; - - if (!string_in_array (subpaths, subpath)) - g_ptr_array_add (subpaths, g_steal_pointer (&subpath)); - } + extra_subpaths = flatpak_dir_get_locale_subpaths (self); /* Always remove locale */ delete = TRUE; } - g_ptr_array_add (subpaths, NULL); + subpaths = flatpak_subpaths_merge ((char **)old_subpaths, extra_subpaths); rel = g_new0 (FlatpakRelated, 1); rel->collection_id = g_strdup (extension_collection_id); rel->ref = g_strdup (extension_ref); rel->commit = g_strdup (checksum); - rel->subpaths = (char **)g_ptr_array_free (g_steal_pointer (&subpaths), FALSE); + rel->subpaths = g_steal_pointer (&subpaths); rel->download = download; rel->delete = delete;