[gnome-software/wip/william/update-all: 75/75] Implement gs_plugin_update_all for apt plugin
- From: William Hua <williamhua src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/william/update-all: 75/75] Implement gs_plugin_update_all for apt plugin
- Date: Wed, 6 Apr 2016 17:34:04 +0000 (UTC)
commit b4e851590fc480d02eca126ef81a888dc4bab6dd
Author: William Hua <william hua canonical com>
Date: Wed Apr 6 18:25:04 2016 +0100
Implement gs_plugin_update_all for apt plugin
src/plugins/gs-plugin-apt.c | 71 +++++++++++++++++++++++++++++++-----------
1 files changed, 52 insertions(+), 19 deletions(-)
---
diff --git a/src/plugins/gs-plugin-apt.c b/src/plugins/gs-plugin-apt.c
index d9af67a..3fee99f 100644
--- a/src/plugins/gs-plugin-apt.c
+++ b/src/plugins/gs-plugin-apt.c
@@ -626,7 +626,17 @@ notify_unity_launcher (GsApp *app, const gchar *transaction_path)
}
static gboolean
-aptd_transaction (GsPlugin *plugin, const gchar *method, GsApp *app, GError **error)
+app_is_ours (GsApp *app)
+{
+ const gchar *management_plugin = gs_app_get_management_plugin (app);
+
+ // FIXME: Since appstream marks all packages as owned by PackageKit and we are replacing PackageKit
we need to accept those packages
+ return g_strcmp0 (management_plugin, "PackageKit") == 0 ||
+ g_strcmp0 (management_plugin, "dpkg") == 0;
+}
+
+static gboolean
+aptd_transaction (GsPlugin *plugin, const gchar *method, GsApp *app, GList *apps, GError **error)
{
g_autoptr(GDBusConnection) conn = NULL;
GVariant *parameters;
@@ -635,6 +645,7 @@ aptd_transaction (GsPlugin *plugin, const gchar *method, GsApp *app, GError **er
g_autoptr(GMainLoop) loop = NULL;
guint property_signal, finished_signal;
TransactionData data;
+ GList *i;
conn = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
if (conn == NULL)
@@ -642,10 +653,18 @@ aptd_transaction (GsPlugin *plugin, const gchar *method, GsApp *app, GError **er
if (g_strcmp0 (method, "InstallFile") == 0)
parameters = g_variant_new ("(sb)", gs_app_get_origin (app), TRUE);
- else if (app != NULL) {
+ else if (app != NULL || apps != NULL) {
GVariantBuilder builder;
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")),
- g_variant_builder_add (&builder, "s", gs_app_get_source_default (app));
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
+
+ if (app != NULL)
+ g_variant_builder_add (&builder, "s", gs_app_get_source_default (app));
+
+ for (i = apps; i != NULL; i = i->next) {
+ if (app_is_ours (i->data))
+ g_variant_builder_add (&builder, "s", gs_app_get_source_default (i->data));
+ }
+
parameters = g_variant_new ("(as)", &builder);
} else
parameters = g_variant_new ("()");
@@ -723,16 +742,6 @@ aptd_transaction (GsPlugin *plugin, const gchar *method, GsApp *app, GError **er
return TRUE;
}
-static gboolean
-app_is_ours (GsApp *app)
-{
- const gchar *management_plugin = gs_app_get_management_plugin (app);
-
- // FIXME: Since appstream marks all packages as owned by PackageKit and we are replacing PackageKit
we need to accept those packages
- return g_strcmp0 (management_plugin, "PackageKit") == 0 ||
- g_strcmp0 (management_plugin, "dpkg") == 0;
-}
-
gboolean
gs_plugin_app_install (GsPlugin *plugin,
GsApp *app,
@@ -750,9 +759,9 @@ gs_plugin_app_install (GsPlugin *plugin,
gs_app_set_state (app, AS_APP_STATE_INSTALLING);
if (g_strcmp0 (gs_app_get_management_plugin (app), "PackageKit") == 0)
- success = aptd_transaction (plugin, "InstallPackages", app, error);
+ success = aptd_transaction (plugin, "InstallPackages", app, NULL, error);
else if (g_strcmp0 (gs_app_get_management_plugin (app), "dpkg") == 0)
- success = aptd_transaction (plugin, "InstallFile", app, error);
+ success = aptd_transaction (plugin, "InstallFile", app, NULL, error);
if (success)
gs_app_set_state (app, AS_APP_STATE_INSTALLED);
@@ -775,7 +784,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
return TRUE;
gs_app_set_state (app, AS_APP_STATE_REMOVING);
- if (aptd_transaction (plugin, "RemovePackages", app, error))
+ if (aptd_transaction (plugin, "RemovePackages", app, NULL, error))
gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
else {
gs_app_set_state (app, AS_APP_STATE_INSTALLED);
@@ -795,7 +804,7 @@ gs_plugin_refresh (GsPlugin *plugin,
if ((flags & GS_PLUGIN_REFRESH_FLAGS_UPDATES) == 0)
return TRUE;
- return aptd_transaction (plugin, "UpdateCache", NULL, error);
+ return aptd_transaction (plugin, "UpdateCache", NULL, NULL, error);
}
gboolean
@@ -843,7 +852,7 @@ gs_plugin_app_update (GsPlugin *plugin,
return TRUE;
gs_app_set_state (app, AS_APP_STATE_INSTALLING);
- if (aptd_transaction (plugin, "UpgradePackages", app, error))
+ if (aptd_transaction (plugin, "UpgradePackages", app, NULL, error))
gs_app_set_state (app, AS_APP_STATE_INSTALLED);
else {
gs_app_set_state (app, AS_APP_STATE_UPDATABLE_LIVE);
@@ -854,6 +863,30 @@ gs_plugin_app_update (GsPlugin *plugin,
}
gboolean
+gs_plugin_update_all (GsPlugin *plugin,
+ GList *apps,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GList *i;
+
+ for (i = apps; i != NULL; i = i->next)
+ gs_app_set_state (i->data, AS_APP_STATE_INSTALLING);
+
+ if (aptd_transaction (plugin, "UpgradePackages", NULL, apps, error)) {
+ for (i = apps; i != NULL; i = i->next)
+ gs_app_set_state (i->data, AS_APP_STATE_INSTALLED);
+
+ return TRUE;
+ } else {
+ for (i = apps; i != NULL; i = i->next)
+ gs_app_set_state (i->data, AS_APP_STATE_UPDATABLE_LIVE);
+
+ return FALSE;
+ }
+}
+
+gboolean
gs_plugin_launch (GsPlugin *plugin,
GsApp *app,
GCancellable *cancellable,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]