[gnome-software: 5/8] packagekit: Merge packagekit-url-to-app plugin into packagekit
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 5/8] packagekit: Merge packagekit-url-to-app plugin into packagekit
- Date: Thu, 10 Jun 2021 12:18:50 +0000 (UTC)
commit 860be508a5a662be747a53ec04669d17a2c4d5fb
Author: Philip Withnall <pwithnall endlessos org>
Date: Thu May 20 15:39:53 2021 +0100
packagekit: Merge packagekit-url-to-app plugin into packagekit
Signed-off-by: Philip Withnall <pwithnall endlessos org>
contrib/gnome-software.spec.in | 1 -
.../packagekit/gs-plugin-packagekit-url-to-app.c | 127 ---------------------
plugins/packagekit/gs-plugin-packagekit.c | 105 ++++++++++++++++-
plugins/packagekit/meson.build | 17 ---
plugins/rpm-ostree/gs-plugin-rpm-ostree.c | 1 -
5 files changed, 104 insertions(+), 147 deletions(-)
---
diff --git a/contrib/gnome-software.spec.in b/contrib/gnome-software.spec.in
index 4f5af478c..9aaaa2e8e 100644
--- a/contrib/gnome-software.spec.in
+++ b/contrib/gnome-software.spec.in
@@ -167,7 +167,6 @@ desktop-file-validate %{buildroot}%{_datadir}/applications/*.desktop
%{gs_plugin_dir}/libgs_plugin_packagekit-refine-repos.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
%{gs_plugin_dir}/libgs_plugin_packagekit.so
%{gs_plugin_dir}/libgs_plugin_provenance-license.so
%{gs_plugin_dir}/libgs_plugin_provenance.so
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 7fda8bf9e..210c95bd9 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -3,6 +3,7 @@
*
* Copyright (C) 2013-2016 Richard Hughes <richard hughsie com>
* Copyright (C) 2014-2018 Kalev Lember <klember redhat com>
+ * Copyright (C) 2017 Canonical Ltd
*
* SPDX-License-Identifier: GPL-2.0+
*/
@@ -20,7 +21,8 @@
/*
* SECTION:
* Uses the system PackageKit instance to return installed packages,
- * sources and the ability to add and remove packages. Supports package history.
+ * sources and the ability to add and remove packages. Supports package history
+ * and converting URIs to apps.
*
* Requires: | [source-id]
* Refines: | [source-id], [source], [update-details], [management-plugin]
@@ -40,6 +42,9 @@ struct GsPluginData {
PkTask *task_local;
GMutex task_mutex_local;
+
+ PkClient *client_url_to_app;
+ GMutex client_mutex_url_to_app;
};
static void gs_plugin_packagekit_updates_changed_cb (PkControl *control, GsPlugin *plugin);
@@ -79,6 +84,14 @@ gs_plugin_initialize (GsPlugin *plugin)
pk_client_set_background (PK_CLIENT (priv->task_local), FALSE);
pk_client_set_interactive (PK_CLIENT (priv->task_local), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+ /* url-to-app */
+ g_mutex_init (&priv->client_mutex_url_to_app);
+ priv->client_url_to_app = pk_client_new ();
+
+ pk_client_set_background (priv->client_url_to_app, FALSE);
+ pk_client_set_cache_age (priv->client_url_to_app, G_MAXUINT);
+ pk_client_set_interactive (priv->client_url_to_app, gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+
/* need pkgname and ID */
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
}
@@ -104,6 +117,10 @@ gs_plugin_destroy (GsPlugin *plugin)
/* local */
g_mutex_clear (&priv->task_mutex_local);
g_object_unref (priv->task_local);
+
+ /* url-to-app */
+ g_mutex_clear (&priv->client_mutex_url_to_app);
+ g_object_unref (priv->client_url_to_app);
}
static gboolean
@@ -2185,3 +2202,89 @@ gs_plugin_add_updates_historical (GsPlugin *plugin,
}
return TRUE;
}
+
+gboolean
+gs_plugin_url_to_app (GsPlugin *plugin,
+ GsAppList *list,
+ const gchar *url,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+
+ g_autofree gchar *scheme = NULL;
+ g_autofree gchar *path = NULL;
+ const gchar *id = NULL;
+ const gchar * const *id_like = NULL;
+ g_auto(GStrv) package_ids = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GsApp) app = NULL;
+ g_autoptr(GsOsRelease) os_release = NULL;
+ g_autoptr(GPtrArray) packages = NULL;
+ g_autoptr(GPtrArray) details = NULL;
+ g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
+
+ path = gs_utils_get_url_path (url);
+
+ /* only do this for apt:// on debian or debian-like distros */
+ os_release = gs_os_release_new (error);
+ if (os_release == NULL) {
+ g_prefix_error (error, "failed to determine OS information:");
+ return FALSE;
+ } else {
+ id = gs_os_release_get_id (os_release);
+ id_like = gs_os_release_get_id_like (os_release);
+ scheme = gs_utils_get_url_scheme (url);
+ if (!(g_strcmp0 (scheme, "apt") == 0 &&
+ (g_strcmp0 (id, "debian") == 0 ||
+ g_strv_contains (id_like, "debian")))) {
+ return TRUE;
+ }
+ }
+
+ app = gs_app_new (NULL);
+ gs_plugin_packagekit_set_packaging_format (plugin, app);
+ gs_app_add_source (app, path);
+ gs_app_set_kind (app, AS_COMPONENT_KIND_GENERIC);
+ gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_PACKAGE);
+
+ package_ids = g_new0 (gchar *, 2);
+ package_ids[0] = g_strdup (path);
+
+ g_mutex_lock (&priv->client_mutex_url_to_app);
+ pk_client_set_interactive (priv->client_url_to_app, gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+ results = pk_client_resolve (priv->client_url_to_app,
+ pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST, PK_FILTER_ENUM_ARCH, -1),
+ package_ids,
+ cancellable,
+ gs_packagekit_helper_cb, helper,
+ error);
+ g_mutex_unlock (&priv->client_mutex_url_to_app);
+
+ 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);
+ details = pk_results_get_details_array (results);
+
+ if (packages->len >= 1) {
+ g_autoptr(GHashTable) details_collection = NULL;
+
+ if (gs_app_get_local_file (app) != NULL)
+ return TRUE;
+
+ details_collection = gs_plugin_packagekit_details_array_to_hash (details);
+
+ gs_plugin_packagekit_resolve_packages_app (plugin, packages, app);
+ gs_plugin_packagekit_refine_details_app (plugin, details_collection, app);
+
+ gs_app_list_add (list, app);
+ } else {
+ g_warning ("no results returned");
+ }
+
+ return TRUE;
+}
diff --git a/plugins/packagekit/meson.build b/plugins/packagekit/meson.build
index 9378b8b01..1b6d17c13 100644
--- a/plugins/packagekit/meson.build
+++ b/plugins/packagekit/meson.build
@@ -108,23 +108,6 @@ sources : 'gs-plugin-packagekit-proxy.c',
dependencies : [ plugin_libs, packagekit ],
)
-shared_module(
- 'gs_plugin_packagekit-url-to-app',
- sources : [
- 'gs-plugin-packagekit-url-to-app.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 : [ plugin_libs, packagekit ],
-)
-
if get_option('tests')
cargs += ['-DTESTDATADIR="' + join_paths(meson.current_source_dir(), 'tests') + '"']
e = executable(
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index 06f07754d..90874593b 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-refine-repos");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-refresh");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-upgrade");
- gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-url-to-app");
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "systemd-updates");
/* need pkgname */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]