[gnome-software/998-flatpak-cover-addons-on-install-uninstall-of-the-application] flatpak: Cover addons on install/uninstall of the application
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/998-flatpak-cover-addons-on-install-uninstall-of-the-application] flatpak: Cover addons on install/uninstall of the application
- Date: Thu, 21 Jan 2021 14:57:03 +0000 (UTC)
commit 758a0e20402bb13cb4b3c2a8d68af8d4d112aa89
Author: Milan Crha <mcrha redhat com>
Date: Thu Jan 21 15:55:19 2021 +0100
flatpak: Cover addons on install/uninstall of the application
When installing/uninstalling an application install/uninstall
also its addons - those being checked for install on install,
those being installed on uninstall.
Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/998
plugins/flatpak/gs-flatpak.c | 31 +++++++++++++++++++++
plugins/flatpak/gs-flatpak.h | 5 ++++
plugins/flatpak/gs-plugin-flatpak.c | 54 +++++++++++++++++++++++++++++++++++++
3 files changed, 90 insertions(+)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 3df3c740..18f6f33d 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2734,6 +2734,37 @@ gs_flatpak_refine_app_unlocked (GsFlatpak *self,
return TRUE;
}
+void
+gs_flatpak_refine_addons (GsFlatpak *self,
+ GsApp *parent_app,
+ GsPluginRefineFlags flags,
+ GsAppState state,
+ GCancellable *cancellable)
+{
+ GsAppList *addons;
+ guint ii, sz;
+
+ addons = gs_app_get_addons (parent_app);
+ sz = addons ? gs_app_list_length (addons) : 0;
+
+ for (ii = 0; ii < sz; ii++) {
+ GsApp *addon = gs_app_list_index (addons, ii);
+ g_autoptr(GError) local_error = NULL;
+
+ if (state != gs_app_get_state (addon))
+ continue;
+
+ /* To have refined also the state */
+ gs_app_set_state (addon, GS_APP_STATE_UNKNOWN);
+
+ if (!gs_flatpak_refine_app_unlocked (self, addon, flags, cancellable, &local_error)) {
+ g_warning ("flatpak-plugin: Failed to refine addon '%s': %s",
+ gs_app_get_name (addon),
+ local_error ? local_error->message : "Unknown error");
+ }
+ }
+}
+
gboolean
gs_flatpak_refine_app (GsFlatpak *self,
GsApp *app,
diff --git a/plugins/flatpak/gs-flatpak.h b/plugins/flatpak/gs-flatpak.h
index e5af289e..15bdd0a0 100644
--- a/plugins/flatpak/gs-flatpak.h
+++ b/plugins/flatpak/gs-flatpak.h
@@ -58,6 +58,11 @@ gboolean gs_flatpak_refine_app (GsFlatpak *self,
GsPluginRefineFlags flags,
GCancellable *cancellable,
GError **error);
+void gs_flatpak_refine_addons (GsFlatpak *self,
+ GsApp *parent_app,
+ GsPluginRefineFlags flags,
+ GsAppState state,
+ GCancellable *cancellable);
gboolean gs_flatpak_refine_app_state (GsFlatpak *self,
GsApp *app,
GCancellable *cancellable,
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index e3d7805e..3c923ca5 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -731,6 +731,50 @@ gs_plugin_download (GsPlugin *plugin, GsAppList *list,
return TRUE;
}
+static void
+gs_flatpak_cover_addons_in_transaction (FlatpakTransaction *transaction,
+ GsApp *parent_app,
+ GsAppState state)
+{
+ GsAppList *addons;
+ guint ii, sz;
+
+ g_return_if_fail (transaction != NULL);
+ g_return_if_fail (GS_IS_APP (parent_app));
+
+ addons = gs_app_get_addons (parent_app);
+ sz = addons ? gs_app_list_length (addons) : 0;
+
+ for (ii = 0; ii < sz; ii++) {
+ GsApp *addon = gs_app_list_index (addons, ii);
+ g_autoptr(GError) local_error = NULL;
+
+ if (state == GS_APP_STATE_INSTALLING && gs_app_get_to_be_installed (addon)) {
+ g_autofree gchar *ref = NULL;
+
+ ref = gs_flatpak_app_get_ref_display (addon);
+ if (flatpak_transaction_add_install (transaction, gs_app_get_origin (addon), ref,
NULL, &local_error)) {
+ gs_app_set_state (addon, state);
+ } else {
+ g_warning ("flatpak-plugin: Failed to add to install for addon '%s': %s",
+ gs_app_get_name (addon),
+ local_error ? local_error->message : "Unknown error");
+ }
+ } else if (state == GS_APP_STATE_REMOVING && gs_app_get_state (addon) ==
GS_APP_STATE_INSTALLED) {
+ g_autofree gchar *ref = NULL;
+
+ ref = gs_flatpak_app_get_ref_display (addon);
+ if (flatpak_transaction_add_uninstall (transaction, ref, &local_error)) {
+ gs_app_set_state (addon, state);
+ } else {
+ g_warning ("flatpak-plugin: Failed to add to uninstall for addon '%s': %s",
+ gs_app_get_name (addon),
+ local_error ? local_error->message : "Unknown error");
+ }
+ }
+ }
+}
+
gboolean
gs_plugin_app_remove (GsPlugin *plugin,
GsApp *app,
@@ -767,6 +811,8 @@ gs_plugin_app_remove (GsPlugin *plugin,
return FALSE;
}
+ gs_flatpak_cover_addons_in_transaction (transaction, app, GS_APP_STATE_REMOVING);
+
/* run transaction */
gs_app_set_state (app, GS_APP_STATE_REMOVING);
if (!gs_flatpak_transaction_run (transaction, cancellable, error)) {
@@ -787,6 +833,9 @@ gs_plugin_app_remove (GsPlugin *plugin,
gs_flatpak_error_convert (error);
return FALSE;
}
+
+ gs_flatpak_refine_addons (flatpak, app, GS_PLUGIN_REFINE_FLAGS_DEFAULT, GS_APP_STATE_REMOVING,
cancellable);
+
return TRUE;
}
@@ -911,6 +960,8 @@ gs_plugin_app_install (GsPlugin *plugin,
}
}
+ gs_flatpak_cover_addons_in_transaction (transaction, app, GS_APP_STATE_INSTALLING);
+
if (!gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE)) {
/* FIXME: Add additional details here, especially the download
* size bounds (using `size-minimum` and `size-maximum`, both
@@ -946,6 +997,9 @@ gs_plugin_app_install (GsPlugin *plugin,
gs_flatpak_error_convert (error);
return FALSE;
}
+
+ gs_flatpak_refine_addons (flatpak, app, GS_PLUGIN_REFINE_FLAGS_DEFAULT, GS_APP_STATE_INSTALLING,
cancellable);
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]