[gnome-software] trivial: Don't set the unique-id directly
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Don't set the unique-id directly
- Date: Tue, 9 Aug 2016 16:23:00 +0000 (UTC)
commit 7acb61c0b35d67ef633be46506e35e76e6ca7e8e
Author: Richard Hughes <richard hughsie com>
Date: Tue Aug 9 16:35:15 2016 +0100
trivial: Don't set the unique-id directly
src/gs-app-private.h | 2 +
src/gs-app.h | 2 -
src/gs-plugin-loader.c | 3 +-
src/plugins/gs-appstream.c | 36 +++++++++++++++++++++++++---
src/plugins/gs-flatpak.c | 2 -
src/plugins/gs-plugin-appstream.c | 16 +++++--------
src/plugins/gs-plugin-flatpak-system.c | 4 +-
src/plugins/gs-plugin-flatpak-user.c | 4 +-
src/plugins/gs-plugin-packagekit-refine.c | 4 +-
9 files changed, 47 insertions(+), 26 deletions(-)
---
diff --git a/src/gs-app-private.h b/src/gs-app-private.h
index 53e168c..9fb8391 100644
--- a/src/gs-app-private.h
+++ b/src/gs-app-private.h
@@ -32,6 +32,8 @@ void gs_app_set_last_error (GsApp *app,
void gs_app_set_priority (GsApp *app,
guint priority);
guint gs_app_get_priority (GsApp *app);
+void gs_app_set_unique_id (GsApp *app,
+ const gchar *unique_id);
G_END_DECLS
diff --git a/src/gs-app.h b/src/gs-app.h
index 1842bad..cf0dae1 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -120,8 +120,6 @@ guint gs_app_get_progress (GsApp *app);
void gs_app_set_progress (GsApp *app,
guint percentage);
const gchar *gs_app_get_unique_id (GsApp *app);
-void gs_app_set_unique_id (GsApp *app,
- const gchar *unique_id);
const gchar *gs_app_get_branch (GsApp *app);
void gs_app_set_branch (GsApp *app,
const gchar *branch);
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 33c7e09..7dded0c 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -181,8 +181,7 @@ gs_plugin_loader_app_sort_name_cb (GsApp *app1, GsApp *app2, gpointer user_data)
static gint
gs_plugin_loader_app_sort_id_cb (GsApp *app1, GsApp *app2, gpointer user_data)
{
- return g_strcmp0 (gs_app_get_unique_id (app1),
- gs_app_get_unique_id (app2));
+ return g_strcmp0 (gs_app_get_id (app1), gs_app_get_id (app2));
}
static GsPlugin *
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index a9f0f82..affdfda 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -455,6 +455,29 @@ _gs_utils_locale_has_translations (const gchar *locale)
return TRUE;
}
+static AsBundleKind
+gs_appstream_get_bundle_kind (AsApp *item)
+{
+ GPtrArray *bundles;
+ GPtrArray *pkgnames;
+
+ /* prefer bundle */
+ bundles = as_app_get_bundles (item);
+ if (bundles->len > 0) {
+ AsBundle *bundle = g_ptr_array_index (bundles, 0);
+ if (as_bundle_get_kind (bundle) != AS_BUNDLE_KIND_UNKNOWN)
+ return as_bundle_get_kind (bundle);
+ }
+
+ /* fallback to packages */
+ pkgnames = as_app_get_pkgnames (item);
+ if (pkgnames->len > 0)
+ return AS_BUNDLE_KIND_PACKAGE;
+
+ /* nothing */
+ return AS_BUNDLE_KIND_UNKNOWN;
+}
+
gboolean
gs_appstream_refine_app (GsPlugin *plugin,
GsApp *app,
@@ -512,13 +535,18 @@ gs_appstream_refine_app (GsPlugin *plugin,
if (as_app_get_id (item) != NULL && gs_app_get_id (app) == NULL)
gs_app_set_id (app, as_app_get_id (item));
- /* set unique-id */
- if (as_app_get_unique_id (item) != NULL && gs_app_get_unique_id (app) == NULL)
- gs_app_set_unique_id (app, as_app_get_unique_id (item));
-
/* set source */
gs_app_set_metadata (app, "appstream::source-file", as_app_get_source_file (item));
+ /* scope */
+ if (gs_app_get_scope (app) == AS_APP_SCOPE_UNKNOWN &&
+ as_app_get_scope (item) != AS_APP_SCOPE_UNKNOWN)
+ gs_app_set_scope (app, as_app_get_scope (item));
+
+ /* bundle-kind */
+ if (gs_app_get_bundle_kind (app) == AS_BUNDLE_KIND_UNKNOWN)
+ gs_app_set_bundle_kind (app, gs_appstream_get_bundle_kind (item));
+
/* set name */
tmp = as_app_get_name (item, NULL);
if (tmp != NULL)
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 7a7d5e9..b0ee7ff 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -362,7 +362,6 @@ gs_flatpak_create_installed (GsFlatpak *self,
if (app == NULL) {
g_autofree gchar *id = gs_flatpak_build_id (FLATPAK_REF (xref));
app = gs_app_new (id);
- gs_app_set_unique_id (app, unique_id);
gs_plugin_cache_add (self->plugin, unique_id, app);
}
gs_flatpak_set_metadata_installed (self, app, xref);
@@ -1643,7 +1642,6 @@ gs_flatpak_file_to_app_bundle (GsFlatpak *self,
if (app == NULL) {
g_autofree gchar *id = gs_flatpak_build_id (FLATPAK_REF (xref_bundle));
app = gs_app_new (id);
- gs_app_set_unique_id (app, unique_id);
gs_plugin_cache_add (self->plugin, unique_id, app);
}
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 3b0afb4..ff2adfe 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -279,19 +279,16 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
/* add keyword for non-package sources */
for (i = 0; i < items->len; i++) {
- g_auto(GStrv) split = NULL;
+ AsBundle *bundle;
app = g_ptr_array_index (items, i);
- split = g_strsplit (as_app_get_unique_id (app), "/", -1);
- if (g_strv_length (split) != 8)
- continue;
- if (g_strcmp0 (split[1], "package") == 0)
- continue;
- if (g_strcmp0 (split[1], "*") == 0)
+ bundle = as_app_get_bundle_default (app);
+ if (bundle == NULL)
continue;
g_debug ("Adding keyword '%s' to %s",
- split[1],
+ as_bundle_kind_to_string (as_bundle_get_kind (bundle)),
as_app_get_unique_id (app));
- as_app_add_keyword (app, NULL, split[1]);
+ as_app_add_keyword (app, NULL,
+ as_bundle_kind_to_string (as_bundle_get_kind (bundle)));
}
/* fix up these */
@@ -399,7 +396,6 @@ gs_plugin_appstream_create_app (GsPlugin *plugin, AsApp *item)
GsApp *app = gs_plugin_cache_lookup (plugin, unique_id);
if (app == NULL) {
app = gs_app_new (as_app_get_id (item));
- gs_app_set_unique_id (app, unique_id);
gs_app_set_metadata (app, "GnomeSoftware::Creator",
gs_plugin_get_name (plugin));
gs_plugin_cache_add (plugin, unique_id, app);
diff --git a/src/plugins/gs-plugin-flatpak-system.c b/src/plugins/gs-plugin-flatpak-system.c
index 4e27561..2d6eae9 100644
--- a/src/plugins/gs-plugin-flatpak-system.c
+++ b/src/plugins/gs-plugin-flatpak-system.c
@@ -64,8 +64,8 @@ gs_plugin_destroy (GsPlugin *plugin)
void
gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
{
- const gchar *id = gs_app_get_unique_id (app);
- if (id != NULL && g_str_has_prefix (id, "system/flatpak/")) {
+ if (gs_app_get_bundle_kind (app) == AS_BUNDLE_KIND_FLATPAK &&
+ gs_app_get_scope (app) == AS_APP_SCOPE_SYSTEM) {
gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
}
}
diff --git a/src/plugins/gs-plugin-flatpak-user.c b/src/plugins/gs-plugin-flatpak-user.c
index 5b63cd1..3b64858 100644
--- a/src/plugins/gs-plugin-flatpak-user.c
+++ b/src/plugins/gs-plugin-flatpak-user.c
@@ -64,8 +64,8 @@ gs_plugin_destroy (GsPlugin *plugin)
void
gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
{
- const gchar *id = gs_app_get_unique_id (app);
- if (id != NULL && g_str_has_prefix (id, "user/flatpak/")) {
+ if (gs_app_get_bundle_kind (app) == AS_BUNDLE_KIND_FLATPAK &&
+ gs_app_get_scope (app) == AS_APP_SCOPE_USER) {
gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
}
}
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 0f7658f..b184696 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -83,8 +83,8 @@ gs_plugin_destroy (GsPlugin *plugin)
void
gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
{
- const gchar *id = gs_app_get_unique_id (app);
- if (id != NULL && g_str_has_prefix (id, "system/package/")) {
+ if (gs_app_get_bundle_kind (app) == AS_BUNDLE_KIND_PACKAGE &&
+ gs_app_get_scope (app) == AS_APP_SCOPE_SYSTEM) {
gs_app_set_management_plugin (app, "packagekit");
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]