[gnome-software: 1/8] packagekit: Merge packagekit-refine plugin into packagekit
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 1/8] packagekit: Merge packagekit-refine plugin into packagekit
- Date: Thu, 10 Jun 2021 12:18:49 +0000 (UTC)
commit 7e160a48c98ab0d84e9c795d50784b672f8d19ec
Author: Philip Withnall <pwithnall endlessos org>
Date: Thu May 20 14:57:52 2021 +0100
packagekit: Merge packagekit-refine plugin into packagekit
This is the first step towards merging all the PackageKit plugins
together so they can share resources and locking.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
contrib/gnome-software.spec.in | 1 -
plugins/core/gs-plugin-generic-updates.c | 2 +-
plugins/core/gs-plugin-provenance.c | 2 +-
plugins/packagekit/gs-plugin-packagekit-refine.c | 845 -----------------------
plugins/packagekit/gs-plugin-packagekit.c | 813 ++++++++++++++++++++++
plugins/packagekit/gs-plugin-systemd-updates.c | 2 +-
plugins/packagekit/meson.build | 19 +-
plugins/repos/gs-plugin-repos.c | 2 +-
plugins/rpm-ostree/gs-plugin-rpm-ostree.c | 1 -
9 files changed, 818 insertions(+), 869 deletions(-)
---
diff --git a/contrib/gnome-software.spec.in b/contrib/gnome-software.spec.in
index 6bc8c0180..933adea6e 100644
--- a/contrib/gnome-software.spec.in
+++ b/contrib/gnome-software.spec.in
@@ -168,7 +168,6 @@ desktop-file-validate %{buildroot}%{_datadir}/applications/*.desktop
%{gs_plugin_dir}/libgs_plugin_packagekit-offline.so
%{gs_plugin_dir}/libgs_plugin_packagekit-proxy.so
%{gs_plugin_dir}/libgs_plugin_packagekit-refine-repos.so
-%{gs_plugin_dir}/libgs_plugin_packagekit-refine.so
%{gs_plugin_dir}/libgs_plugin_packagekit-refresh.so
%{gs_plugin_dir}/libgs_plugin_packagekit-upgrade.so
%{gs_plugin_dir}/libgs_plugin_packagekit-url-to-app.so
diff --git a/plugins/core/gs-plugin-generic-updates.c b/plugins/core/gs-plugin-generic-updates.c
index bb05492a5..7559b58c6 100644
--- a/plugins/core/gs-plugin-generic-updates.c
+++ b/plugins/core/gs-plugin-generic-updates.c
@@ -15,7 +15,7 @@ void
gs_plugin_initialize (GsPlugin *plugin)
{
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
- gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit-refine");
+ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "rpm-ostree");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "icons");
}
diff --git a/plugins/core/gs-plugin-provenance.c b/plugins/core/gs-plugin-provenance.c
index 03a854b8c..cde5932f4 100644
--- a/plugins/core/gs-plugin-provenance.c
+++ b/plugins/core/gs-plugin-provenance.c
@@ -58,7 +58,7 @@ gs_plugin_initialize (GsPlugin *plugin)
/* after the package source is set */
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "dummy");
- gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit-refine");
+ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "rpm-ostree");
}
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 4185198bd..a6fbca4f3 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -14,6 +14,7 @@
#include <gnome-software.h>
#include "packagekit-common.h"
+#include "gs-markdown.h"
#include "gs-packagekit-helper.h"
/*
@@ -28,26 +29,56 @@
struct GsPluginData {
PkTask *task;
GMutex task_mutex;
+
+ PkControl *control_refine;
+ PkClient *client_refine;
+ GMutex client_mutex_refine;
};
+static void gs_plugin_packagekit_updates_changed_cb (PkControl *control, GsPlugin *plugin);
+static void gs_plugin_packagekit_repo_list_changed_cb (PkControl *control, GsPlugin *plugin);
+
void
gs_plugin_initialize (GsPlugin *plugin)
{
GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ /* core */
g_mutex_init (&priv->task_mutex);
priv->task = pk_task_new ();
pk_client_set_background (PK_CLIENT (priv->task), FALSE);
pk_client_set_cache_age (PK_CLIENT (priv->task), G_MAXUINT);
pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+
+ /* refine */
+ g_mutex_init (&priv->client_mutex_refine);
+ priv->client_refine = pk_client_new ();
+ priv->control_refine = pk_control_new ();
+ g_signal_connect (priv->control_refine, "updates-changed",
+ G_CALLBACK (gs_plugin_packagekit_updates_changed_cb), plugin);
+ g_signal_connect (priv->control_refine, "repo-list-changed",
+ G_CALLBACK (gs_plugin_packagekit_repo_list_changed_cb), plugin);
+ pk_client_set_background (priv->client_refine, FALSE);
+ pk_client_set_cache_age (priv->client_refine, G_MAXUINT);
+ pk_client_set_interactive (priv->client_refine, gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+
+ /* need pkgname and ID */
+ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
}
void
gs_plugin_destroy (GsPlugin *plugin)
{
GsPluginData *priv = gs_plugin_get_data (plugin);
+
+ /* core */
g_mutex_clear (&priv->task_mutex);
g_object_unref (priv->task);
+
+ /* refine */
+ g_mutex_clear (&priv->client_mutex_refine);
+ g_object_unref (priv->client_refine);
+ g_object_unref (priv->control_refine);
}
static gboolean
@@ -753,3 +784,785 @@ gs_plugin_launch (GsPlugin *plugin,
return TRUE;
return gs_plugin_app_launch (plugin, app, error);
}
+
+static void
+gs_plugin_packagekit_updates_changed_cb (PkControl *control, GsPlugin *plugin)
+{
+ gs_plugin_updates_changed (plugin);
+}
+
+static void
+gs_plugin_packagekit_repo_list_changed_cb (PkControl *control, GsPlugin *plugin)
+{
+ gs_plugin_reload (plugin);
+}
+
+void
+gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
+{
+ if (gs_app_get_bundle_kind (app) == AS_BUNDLE_KIND_PACKAGE &&
+ gs_app_get_scope (app) == AS_COMPONENT_SCOPE_SYSTEM) {
+ gs_app_set_management_plugin (app, "packagekit");
+ gs_plugin_packagekit_set_packaging_format (plugin, app);
+ return;
+ }
+}
+
+static gboolean
+gs_plugin_packagekit_resolve_packages_with_filter (GsPlugin *plugin,
+ GsAppList *list,
+ PkBitfield filter,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ GPtrArray *sources;
+ GsApp *app;
+ const gchar *pkgname;
+ guint i;
+ guint j;
+ g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GPtrArray) package_ids = NULL;
+ g_autoptr(GPtrArray) packages = NULL;
+
+ package_ids = g_ptr_array_new_with_free_func (g_free);
+ for (i = 0; i < gs_app_list_length (list); i++) {
+ app = gs_app_list_index (list, i);
+ sources = gs_app_get_sources (app);
+ for (j = 0; j < sources->len; j++) {
+ pkgname = g_ptr_array_index (sources, j);
+ if (pkgname == NULL || pkgname[0] == '\0') {
+ g_warning ("invalid pkgname '%s' for %s",
+ pkgname,
+ gs_app_get_unique_id (app));
+ continue;
+ }
+ g_ptr_array_add (package_ids, g_strdup (pkgname));
+ }
+ }
+ if (package_ids->len == 0)
+ return TRUE;
+ g_ptr_array_add (package_ids, NULL);
+
+ /* resolve them all at once */
+ g_mutex_lock (&priv->client_mutex_refine);
+ results = pk_client_resolve (priv->client_refine,
+ filter,
+ (gchar **) package_ids->pdata,
+ cancellable,
+ gs_packagekit_helper_cb, helper,
+ error);
+ g_mutex_unlock (&priv->client_mutex_refine);
+ if (!gs_plugin_packagekit_results_valid (results, error)) {
+ g_prefix_error (error, "failed to resolve package_ids: ");
+ return FALSE;
+ }
+
+ /* get results */
+ packages = pk_results_get_package_array (results);
+
+ /* if the user types more characters we'll get cancelled - don't go on
+ * to mark apps as unavailable because packages->len = 0 */
+ if (g_cancellable_set_error_if_cancelled (cancellable, error)) {
+ gs_utils_error_convert_gio (error);
+ return FALSE;
+ }
+
+ for (i = 0; i < gs_app_list_length (list); i++) {
+ app = gs_app_list_index (list, i);
+ if (gs_app_get_local_file (app) != NULL)
+ continue;
+ gs_plugin_packagekit_resolve_packages_app (plugin, packages, app);
+ }
+ return TRUE;
+}
+
+static gboolean
+gs_plugin_packagekit_resolve_packages (GsPlugin *plugin,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ PkBitfield filter;
+ g_autoptr(GsAppList) resolve2_list = NULL;
+
+ /* first, try to resolve packages with ARCH filter */
+ filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST,
+ PK_FILTER_ENUM_ARCH,
+ -1);
+ if (!gs_plugin_packagekit_resolve_packages_with_filter (plugin,
+ list,
+ filter,
+ cancellable,
+ error)) {
+ return FALSE;
+ }
+
+ /* if any packages remaining in UNKNOWN state, try to resolve them again,
+ * but this time without ARCH filter */
+ resolve2_list = gs_app_list_new ();
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ if (gs_app_get_state (app) == GS_APP_STATE_UNKNOWN)
+ gs_app_list_add (resolve2_list, app);
+ }
+ filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST,
+ PK_FILTER_ENUM_NOT_ARCH,
+ PK_FILTER_ENUM_NOT_SOURCE,
+ -1);
+ if (!gs_plugin_packagekit_resolve_packages_with_filter (plugin,
+ resolve2_list,
+ filter,
+ cancellable,
+ error)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+gs_plugin_packagekit_refine_from_desktop (GsPlugin *plugin,
+ GsApp *app,
+ const gchar *filename,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ const gchar *to_array[] = { NULL, NULL };
+ g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GPtrArray) packages = NULL;
+
+ to_array[0] = filename;
+ gs_packagekit_helper_add_app (helper, app);
+ g_mutex_lock (&priv->client_mutex_refine);
+ results = pk_client_search_files (priv->client_refine,
+ pk_bitfield_from_enums (PK_FILTER_ENUM_INSTALLED, -1),
+ (gchar **) to_array,
+ cancellable,
+ gs_packagekit_helper_cb, helper,
+ error);
+ g_mutex_unlock (&priv->client_mutex_refine);
+ if (!gs_plugin_packagekit_results_valid (results, error)) {
+ g_prefix_error (error, "failed to search file %s: ", filename);
+ return FALSE;
+ }
+
+ /* get results */
+ packages = pk_results_get_package_array (results);
+ if (packages->len == 1) {
+ PkPackage *package;
+ package = g_ptr_array_index (packages, 0);
+ gs_plugin_packagekit_set_metadata_from_package (plugin, app, package);
+ } else {
+ g_warning ("Failed to find one package for %s, %s, [%u]",
+ gs_app_get_id (app), filename, packages->len);
+ }
+ return TRUE;
+}
+
+/*
+ * gs_plugin_packagekit_fixup_update_description:
+ *
+ * Lets assume Fedora is sending us valid markdown, but fall back to
+ * plain text if this fails.
+ */
+static gchar *
+gs_plugin_packagekit_fixup_update_description (const gchar *text)
+{
+ gchar *tmp;
+ g_autoptr(GsMarkdown) markdown = NULL;
+
+ /* nothing to do */
+ if (text == NULL)
+ return NULL;
+
+ /* try to parse */
+ markdown = gs_markdown_new (GS_MARKDOWN_OUTPUT_TEXT);
+ gs_markdown_set_smart_quoting (markdown, FALSE);
+ gs_markdown_set_autocode (markdown, FALSE);
+ gs_markdown_set_autolinkify (markdown, FALSE);
+ tmp = gs_markdown_parse (markdown, text);
+ if (tmp != NULL)
+ return tmp;
+ return g_strdup (text);
+}
+
+static gboolean
+gs_plugin_packagekit_refine_updatedetails (GsPlugin *plugin,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ const gchar *package_id;
+ guint j;
+ GsApp *app;
+ guint cnt = 0;
+ PkUpdateDetail *update_detail;
+ g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
+ g_autofree const gchar **package_ids = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GPtrArray) array = NULL;
+
+ package_ids = g_new0 (const gchar *, gs_app_list_length (list) + 1);
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ app = gs_app_list_index (list, i);
+ package_id = gs_app_get_source_id_default (app);
+ if (package_id != NULL)
+ package_ids[cnt++] = package_id;
+ }
+
+ /* nothing to do */
+ if (cnt == 0)
+ return TRUE;
+
+ /* get any update details */
+ g_mutex_lock (&priv->client_mutex_refine);
+ results = pk_client_get_update_detail (priv->client_refine,
+ (gchar **) package_ids,
+ cancellable,
+ gs_packagekit_helper_cb, helper,
+ error);
+ g_mutex_unlock (&priv->client_mutex_refine);
+ if (!gs_plugin_packagekit_results_valid (results, error)) {
+ g_prefix_error (error, "failed to get update details for %s: ",
+ package_ids[0]);
+ return FALSE;
+ }
+
+ /* set the update details for the update */
+ array = pk_results_get_update_detail_array (results);
+ for (j = 0; j < gs_app_list_length (list); j++) {
+ app = gs_app_list_index (list, j);
+ package_id = gs_app_get_source_id_default (app);
+ for (guint i = 0; i < array->len; i++) {
+ const gchar *tmp;
+ g_autofree gchar *desc = NULL;
+ /* right package? */
+ update_detail = g_ptr_array_index (array, i);
+ if (g_strcmp0 (package_id, pk_update_detail_get_package_id (update_detail)) != 0)
+ continue;
+ tmp = pk_update_detail_get_update_text (update_detail);
+ desc = gs_plugin_packagekit_fixup_update_description (tmp);
+ if (desc != NULL)
+ gs_app_set_update_details (app, desc);
+ break;
+ }
+ }
+ return TRUE;
+}
+
+static gboolean
+gs_plugin_packagekit_refine_details2 (GsPlugin *plugin,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ GPtrArray *source_ids;
+ GsApp *app;
+ const gchar *package_id;
+ guint i, j;
+ g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
+ g_autoptr(GPtrArray) array = NULL;
+ g_autoptr(GPtrArray) package_ids = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GHashTable) details_collection = NULL;
+
+ package_ids = g_ptr_array_new_with_free_func (g_free);
+ for (i = 0; i < gs_app_list_length (list); i++) {
+ app = gs_app_list_index (list, i);
+ source_ids = gs_app_get_source_ids (app);
+ for (j = 0; j < source_ids->len; j++) {
+ package_id = g_ptr_array_index (source_ids, j);
+ g_ptr_array_add (package_ids, g_strdup (package_id));
+ }
+ }
+ if (package_ids->len == 0)
+ return TRUE;
+ g_ptr_array_add (package_ids, NULL);
+
+ /* get any details */
+ g_mutex_lock (&priv->client_mutex_refine);
+ results = pk_client_get_details (priv->client_refine,
+ (gchar **) package_ids->pdata,
+ cancellable,
+ gs_packagekit_helper_cb, helper,
+ error);
+ g_mutex_unlock (&priv->client_mutex_refine);
+ if (!gs_plugin_packagekit_results_valid (results, error)) {
+ g_autofree gchar *package_ids_str = g_strjoinv (",", (gchar **) package_ids->pdata);
+ g_prefix_error (error, "failed to get details for %s: ",
+ package_ids_str);
+ return FALSE;
+ }
+
+ /* get the results and copy them into a hash table for fast lookups:
+ * there are typically 400 to 700 elements in @array, and 100 to 200
+ * elements in @list, each with 1 or 2 source IDs to look up (but
+ * sometimes 200) */
+ array = pk_results_get_details_array (results);
+ details_collection = gs_plugin_packagekit_details_array_to_hash (array);
+
+ /* set the update details for the update */
+ for (i = 0; i < gs_app_list_length (list); i++) {
+ app = gs_app_list_index (list, i);
+ gs_plugin_packagekit_refine_details_app (plugin, details_collection, app);
+ }
+
+ return TRUE;
+}
+
+static gboolean
+gs_plugin_packagekit_refine_update_urgency (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ guint i;
+ GsApp *app;
+ const gchar *package_id;
+ PkBitfield filter;
+ g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
+ g_autoptr(PkPackageSack) sack = NULL;
+ g_autoptr(PkResults) results = NULL;
+
+ /* not required */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_SEVERITY) == 0)
+ return TRUE;
+
+ /* get the list of updates */
+ filter = pk_bitfield_value (PK_FILTER_ENUM_NONE);
+ g_mutex_lock (&priv->client_mutex_refine);
+ results = pk_client_get_updates (priv->client_refine,
+ filter,
+ cancellable,
+ gs_packagekit_helper_cb, helper,
+ error);
+ g_mutex_unlock (&priv->client_mutex_refine);
+ if (!gs_plugin_packagekit_results_valid (results, error)) {
+ g_prefix_error (error, "failed to get updates for urgency: ");
+ return FALSE;
+ }
+
+ /* set the update severity for the app */
+ sack = pk_results_get_package_sack (results);
+ for (i = 0; i < gs_app_list_length (list); i++) {
+ g_autoptr (PkPackage) pkg = NULL;
+ app = gs_app_list_index (list, i);
+ if (gs_app_has_quirk (app, GS_APP_QUIRK_IS_WILDCARD))
+ continue;
+ package_id = gs_app_get_source_id_default (app);
+ if (package_id == NULL)
+ continue;
+ pkg = pk_package_sack_find_by_id (sack, package_id);
+ if (pkg == NULL)
+ continue;
+ #ifdef HAVE_PK_PACKAGE_GET_UPDATE_SEVERITY
+ switch (pk_package_get_update_severity (pkg)) {
+ case PK_INFO_ENUM_LOW:
+ gs_app_set_update_urgency (app, AS_URGENCY_KIND_LOW);
+ break;
+ case PK_INFO_ENUM_NORMAL:
+ gs_app_set_update_urgency (app, AS_URGENCY_KIND_MEDIUM);
+ break;
+ case PK_INFO_ENUM_IMPORTANT:
+ gs_app_set_update_urgency (app, AS_URGENCY_KIND_HIGH);
+ break;
+ case PK_INFO_ENUM_CRITICAL:
+ gs_app_set_update_urgency (app, AS_URGENCY_KIND_CRITICAL);
+ break;
+ default:
+ gs_app_set_update_urgency (app, AS_URGENCY_KIND_UNKNOWN);
+ break;
+ }
+ #else
+ switch (pk_package_get_info (pkg)) {
+ case PK_INFO_ENUM_AVAILABLE:
+ case PK_INFO_ENUM_NORMAL:
+ case PK_INFO_ENUM_LOW:
+ case PK_INFO_ENUM_ENHANCEMENT:
+ gs_app_set_update_urgency (app, AS_URGENCY_KIND_LOW);
+ break;
+ case PK_INFO_ENUM_BUGFIX:
+ gs_app_set_update_urgency (app, AS_URGENCY_KIND_MEDIUM);
+ break;
+ case PK_INFO_ENUM_SECURITY:
+ gs_app_set_update_urgency (app, AS_URGENCY_KIND_CRITICAL);
+ break;
+ case PK_INFO_ENUM_IMPORTANT:
+ gs_app_set_update_urgency (app, AS_URGENCY_KIND_HIGH);
+ break;
+ default:
+ gs_app_set_update_urgency (app, AS_URGENCY_KIND_UNKNOWN);
+ g_warning ("unhandled info state %s",
+ pk_info_enum_to_string (pk_package_get_info (pkg)));
+ break;
+ }
+ #endif
+ }
+ return TRUE;
+}
+
+static gboolean
+gs_plugin_refine_app_needs_details (GsPlugin *plugin, GsPluginRefineFlags flags, GsApp *app)
+{
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE) > 0 &&
+ gs_app_get_license (app) == NULL)
+ return TRUE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_URL) > 0 &&
+ gs_app_get_url (app, AS_URL_KIND_HOMEPAGE) == NULL)
+ return TRUE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE) > 0 &&
+ gs_app_get_size_installed (app) == 0)
+ return TRUE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE) > 0 &&
+ gs_app_get_size_download (app) == 0)
+ return TRUE;
+ return FALSE;
+}
+
+static gboolean
+gs_plugin_packagekit_refine_details (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = TRUE;
+ g_autoptr(GsAppList) list_tmp = NULL;
+
+ list_tmp = gs_app_list_new ();
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ if (gs_app_has_quirk (app, GS_APP_QUIRK_IS_WILDCARD))
+ continue;
+ if (g_strcmp0 (gs_app_get_management_plugin (app), "packagekit") != 0)
+ continue;
+ if (gs_app_get_source_id_default (app) == NULL)
+ continue;
+ if (!gs_plugin_refine_app_needs_details (plugin, flags, app))
+ continue;
+ gs_app_list_add (list_tmp, app);
+ }
+ if (gs_app_list_length (list_tmp) == 0)
+ return TRUE;
+ ret = gs_plugin_packagekit_refine_details2 (plugin,
+ list_tmp,
+ cancellable,
+ error);
+ if (!ret)
+ return FALSE;
+ return TRUE;
+}
+
+static gboolean
+gs_plugin_refine_requires_version (GsApp *app, GsPluginRefineFlags flags)
+{
+ const gchar *tmp;
+ tmp = gs_app_get_version (app);
+ if (tmp != NULL)
+ return FALSE;
+ return (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION) > 0;
+}
+
+static gboolean
+gs_plugin_refine_requires_update_details (GsApp *app, GsPluginRefineFlags flags)
+{
+ const gchar *tmp;
+ tmp = gs_app_get_update_details (app);
+ if (tmp != NULL)
+ return FALSE;
+ return (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS) > 0;
+}
+
+static gboolean
+gs_plugin_refine_requires_origin (GsApp *app, GsPluginRefineFlags flags)
+{
+ const gchar *tmp;
+ tmp = gs_app_get_origin (app);
+ if (tmp != NULL)
+ return FALSE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN) > 0)
+ return TRUE;
+ return FALSE;
+}
+
+static gboolean
+gs_plugin_refine_requires_package_id (GsApp *app, GsPluginRefineFlags flags)
+{
+ const gchar *tmp;
+ tmp = gs_app_get_source_id_default (app);
+ if (tmp != NULL)
+ return FALSE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION) > 0)
+ return TRUE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE) > 0)
+ return TRUE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_URL) > 0)
+ return TRUE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE) > 0)
+ return TRUE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_DESCRIPTION) > 0)
+ return TRUE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION) > 0)
+ return TRUE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS) > 0)
+ return TRUE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) > 0)
+ return TRUE;
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION) > 0)
+ return TRUE;
+ return FALSE;
+}
+
+static gboolean
+gs_plugin_packagekit_refine_distro_upgrade (GsPlugin *plugin,
+ GsApp *app,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ guint i;
+ GsApp *app2;
+ g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GsAppList) list = NULL;
+ guint cache_age_save;
+
+ gs_packagekit_helper_add_app (helper, app);
+
+ /* ask PK to simulate upgrading the system */
+ g_mutex_lock (&priv->client_mutex_refine);
+ cache_age_save = pk_client_get_cache_age (priv->client_refine);
+ pk_client_set_cache_age (priv->client_refine, 60 * 60 * 24 * 7); /* once per week */
+ pk_client_set_interactive (priv->client_refine, gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+ results = pk_client_upgrade_system (priv->client_refine,
+ pk_bitfield_from_enums (PK_TRANSACTION_FLAG_ENUM_SIMULATE, -1),
+ gs_app_get_version (app),
+ PK_UPGRADE_KIND_ENUM_COMPLETE,
+ cancellable,
+ gs_packagekit_helper_cb, helper,
+ error);
+ pk_client_set_cache_age (priv->client_refine, cache_age_save);
+ g_mutex_unlock (&priv->client_mutex_refine);
+
+ if (!gs_plugin_packagekit_results_valid (results, error)) {
+ g_prefix_error (error, "failed to refine distro upgrade: ");
+ return FALSE;
+ }
+ list = gs_app_list_new ();
+ if (!gs_plugin_packagekit_add_results (plugin, list, results, error))
+ return FALSE;
+
+ /* add each of these as related applications */
+ for (i = 0; i < gs_app_list_length (list); i++) {
+ app2 = gs_app_list_index (list, i);
+ if (gs_app_get_state (app2) != GS_APP_STATE_UNAVAILABLE)
+ continue;
+ gs_app_add_related (app, app2);
+ }
+ return TRUE;
+}
+
+static gboolean
+gs_plugin_packagekit_refine_valid_package_name (const gchar *source)
+{
+ if (g_strstr_len (source, -1, "/") != NULL)
+ return FALSE;
+ return TRUE;
+}
+
+static gboolean
+gs_plugin_packagekit_refine_name_to_id (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GsAppList) resolve_all = gs_app_list_new ();
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GPtrArray *sources;
+ GsApp *app = gs_app_list_index (list, i);
+ const gchar *tmp;
+ if (gs_app_has_quirk (app, GS_APP_QUIRK_IS_WILDCARD))
+ continue;
+ tmp = gs_app_get_management_plugin (app);
+ if (tmp != NULL && g_strcmp0 (tmp, "packagekit") != 0)
+ continue;
+ sources = gs_app_get_sources (app);
+ if (sources->len == 0)
+ continue;
+ tmp = g_ptr_array_index (sources, 0);
+ if (!gs_plugin_packagekit_refine_valid_package_name (tmp))
+ continue;
+ if (gs_app_get_state (app) == GS_APP_STATE_UNKNOWN ||
+ gs_plugin_refine_requires_package_id (app, flags) ||
+ gs_plugin_refine_requires_origin (app, flags) ||
+ gs_plugin_refine_requires_version (app, flags)) {
+ gs_app_list_add (resolve_all, app);
+ }
+ }
+ if (gs_app_list_length (resolve_all) > 0) {
+ if (!gs_plugin_packagekit_resolve_packages (plugin,
+ resolve_all,
+ cancellable,
+ error))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static gboolean
+gs_plugin_packagekit_refine_filename_to_id (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* not now */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION) == 0)
+ return TRUE;
+
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ g_autofree gchar *fn = NULL;
+ GsApp *app = gs_app_list_index (list, i);
+ const gchar *tmp;
+ if (gs_app_has_quirk (app, GS_APP_QUIRK_IS_WILDCARD))
+ continue;
+ if (gs_app_get_source_id_default (app) != NULL)
+ continue;
+ tmp = gs_app_get_management_plugin (app);
+ if (tmp != NULL && g_strcmp0 (tmp, "packagekit") != 0)
+ continue;
+ tmp = gs_app_get_id (app);
+ if (tmp == NULL)
+ continue;
+ switch (gs_app_get_kind (app)) {
+ case AS_COMPONENT_KIND_DESKTOP_APP:
+ fn = g_strdup_printf ("/usr/share/applications/%s", tmp);
+ break;
+ case AS_COMPONENT_KIND_ADDON:
+ fn = g_strdup_printf ("/usr/share/metainfo/%s.metainfo.xml", tmp);
+ if (!g_file_test (fn, G_FILE_TEST_EXISTS)) {
+ g_free (fn);
+ fn = g_strdup_printf ("/usr/share/appdata/%s.metainfo.xml", tmp);
+ }
+ break;
+ default:
+ break;
+ }
+ if (fn == NULL)
+ continue;
+ if (!g_file_test (fn, G_FILE_TEST_EXISTS)) {
+ g_debug ("ignoring %s as does not exist", fn);
+ continue;
+ }
+ if (!gs_plugin_packagekit_refine_from_desktop (plugin,
+ app,
+ fn,
+ cancellable,
+ error))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static gboolean
+gs_plugin_packagekit_refine_update_details (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GsAppList) updatedetails_all = gs_app_list_new ();
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ const gchar *tmp;
+ if (gs_app_has_quirk (app, GS_APP_QUIRK_IS_WILDCARD))
+ continue;
+ if (gs_app_get_state (app) != GS_APP_STATE_UPDATABLE)
+ continue;
+ if (gs_app_get_source_id_default (app) == NULL)
+ continue;
+ tmp = gs_app_get_management_plugin (app);
+ if (tmp != NULL && g_strcmp0 (tmp, "packagekit") != 0)
+ continue;
+ if (gs_plugin_refine_requires_update_details (app, flags))
+ gs_app_list_add (updatedetails_all, app);
+ }
+ if (gs_app_list_length (updatedetails_all) > 0) {
+ if (!gs_plugin_packagekit_refine_updatedetails (plugin,
+ updatedetails_all,
+ cancellable,
+ error))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* when we need the cannot-be-upgraded applications, we implement this
+ * by doing a UpgradeSystem(SIMULATE) which adds the removed packages
+ * to the related-apps list with a state of %GS_APP_STATE_UNAVAILABLE */
+ if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPGRADE_REMOVED) {
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ if (gs_app_get_kind (app) != AS_COMPONENT_KIND_OPERATING_SYSTEM)
+ continue;
+ if (!gs_plugin_packagekit_refine_distro_upgrade (plugin,
+ app,
+ cancellable,
+ error))
+ return FALSE;
+ }
+ }
+
+ /* can we resolve in one go? */
+ if (!gs_plugin_packagekit_refine_name_to_id (plugin, list, flags, cancellable, error))
+ return FALSE;
+
+ /* set the package-id for an installed desktop file */
+ if (!gs_plugin_packagekit_refine_filename_to_id (plugin, list, flags, cancellable, error))
+ return FALSE;
+
+ /* any update details missing? */
+ if (!gs_plugin_packagekit_refine_update_details (plugin, list, flags, cancellable, error))
+ return FALSE;
+
+ /* any package details missing? */
+ if (!gs_plugin_packagekit_refine_details (plugin, list, flags, cancellable, error))
+ return FALSE;
+
+ /* get the update severity */
+ if (!gs_plugin_packagekit_refine_update_urgency (plugin, list, flags, cancellable, error))
+ return FALSE;
+
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+
+ /* only process this app if was created by this plugin */
+ if (g_strcmp0 (gs_app_get_management_plugin (app), "packagekit") != 0)
+ continue;
+
+ /* the scope is always system-wide */
+ if (gs_app_get_scope (app) == AS_COMPONENT_SCOPE_UNKNOWN)
+ gs_app_set_scope (app, AS_COMPONENT_SCOPE_SYSTEM);
+ if (gs_app_get_bundle_kind (app) == AS_BUNDLE_KIND_UNKNOWN)
+ gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_PACKAGE);
+ }
+
+ /* success */
+ return TRUE;
+}
diff --git a/plugins/packagekit/gs-plugin-systemd-updates.c b/plugins/packagekit/gs-plugin-systemd-updates.c
index 02dbdf238..ba3b727b0 100644
--- a/plugins/packagekit/gs-plugin-systemd-updates.c
+++ b/plugins/packagekit/gs-plugin-systemd-updates.c
@@ -34,7 +34,7 @@ gs_plugin_initialize (GsPlugin *plugin)
{
GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit-refresh");
- gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit-refine");
+ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "generic-updates");
g_mutex_init (&priv->hash_prepared_mutex);
priv->hash_prepared = g_hash_table_new_full (g_str_hash, g_str_equal,
diff --git a/plugins/packagekit/meson.build b/plugins/packagekit/meson.build
index 74aefaecf..035ab3d57 100644
--- a/plugins/packagekit/meson.build
+++ b/plugins/packagekit/meson.build
@@ -32,24 +32,7 @@ shared_module(
'gs-plugin-packagekit.c',
'gs-packagekit-helper.c',
'packagekit-common.c',
- ],
- include_directories : [
- include_directories('../..'),
- include_directories('../../lib'),
- ],
- install : true,
- install_dir: plugin_dir,
- c_args : cargs,
- dependencies : deps,
-)
-
-shared_module(
- 'gs_plugin_packagekit-refine',
- sources : [
- 'gs-plugin-packagekit-refine.c',
'gs-markdown.c',
- 'gs-packagekit-helper.c',
- 'packagekit-common.c',
],
include_directories : [
include_directories('../..'),
@@ -58,7 +41,7 @@ shared_module(
install : true,
install_dir: plugin_dir,
c_args : cargs,
- dependencies : [ plugin_libs, packagekit ],
+ dependencies : deps,
)
shared_module(
diff --git a/plugins/repos/gs-plugin-repos.c b/plugins/repos/gs-plugin-repos.c
index 10281ee82..e5d5745f3 100644
--- a/plugins/repos/gs-plugin-repos.c
+++ b/plugins/repos/gs-plugin-repos.c
@@ -43,7 +43,7 @@ gs_plugin_initialize (GsPlugin *plugin)
priv->urls = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
/* need application IDs */
- gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit-refine");
+ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "rpm-ostree");
}
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index 0a616eca0..27def5045 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -72,7 +72,6 @@ gs_plugin_initialize (GsPlugin *plugin)
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-local");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-offline");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-proxy");
- gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-refine");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-refine-repos");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-refresh");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-upgrade");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]