[gnome-software] Add the concept of provenance for applications
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add the concept of provenance for applications
- Date: Wed, 9 Dec 2015 16:29:04 +0000 (UTC)
commit dcbc8aef854a5b16f2d79de7258ce4877d59f050
Author: Richard Hughes <richard hughsie com>
Date: Wed Dec 9 11:00:26 2015 +0000
Add the concept of provenance for applications
For this definition, an application has provenance if it originated from the
same place as the OS vendor.
I added this as a "default negative, plugin sets positive" action to allow
applications originating from different plugins to have a different set of
places. For instance, packages would have to match the OS vendor, but xdg-apps
might just have to come from an upstream repo that's been blessed by the OS in
some way.
src/gs-app.c | 19 ++++
src/gs-app.h | 4 +
src/gs-cmd.c | 2 +
src/gs-plugin.h | 1 +
src/gs-shell-installed.c | 1 +
src/gs-shell-search.c | 1 +
src/plugins/Makefile.am | 6 ++
src/plugins/gs-plugin-fedora-provenance.c | 135 +++++++++++++++++++++++++++++
src/plugins/gs-plugin-packagekit-refine.c | 2 +
9 files changed, 171 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 883db8a..6e51a5b 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -100,6 +100,7 @@ struct _GsApp
guint64 install_date;
guint64 kudos;
gboolean to_be_installed;
+ gboolean provenance;
AsBundle *bundle;
};
@@ -2003,6 +2004,24 @@ gs_app_get_bundle (GsApp *app)
}
/**
+ * gs_app_get_provenance:
+ */
+gboolean
+gs_app_get_provenance (GsApp *app)
+{
+ return app->provenance;
+}
+
+/**
+ * gs_app_set_provenance:
+ */
+void
+gs_app_set_provenance (GsApp *app, gboolean provenance)
+{
+ app->provenance = provenance;
+}
+
+/**
* gs_app_subsume:
*
* Imports all the useful data from @other into @app.
diff --git a/src/gs-app.h b/src/gs-app.h
index ca01712..e281533 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -258,6 +258,10 @@ AsBundle *gs_app_get_bundle (GsApp *app);
void gs_app_set_bundle (GsApp *app,
AsBundle *bundle);
+gboolean gs_app_get_provenance (GsApp *app);
+void gs_app_set_provenance (GsApp *app,
+ gboolean provenance);
+
G_END_DECLS
#endif /* __GS_APP_H */
diff --git a/src/gs-cmd.c b/src/gs-cmd.c
index e518cbd..a23d0ef 100644
--- a/src/gs-cmd.c
+++ b/src/gs-cmd.c
@@ -138,6 +138,8 @@ gs_cmd_refine_flag_from_string (const gchar *flag, GError **error)
return GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH;
if (g_strcmp0 (flag, "upgrade-removed") == 0)
return GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPGRADE_REMOVED;
+ if (g_strcmp0 (flag, "provenance") == 0)
+ return GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_NOT_SUPPORTED,
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 94037ce..ebb8a26 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -102,6 +102,7 @@ typedef enum {
GS_PLUGIN_REFINE_FLAGS_ALLOW_PACKAGES = 1 << 14,
GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_SEVERITY = 1 << 15,
GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPGRADE_REMOVED = 1 << 16,
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE = 1 << 17,
GS_PLUGIN_REFINE_FLAGS_LAST
} GsPluginRefineFlags;
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index 4051668..64d8295 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -234,6 +234,7 @@ gs_shell_installed_load (GsShellInstalled *self)
GS_PLUGIN_REFINE_FLAGS_REQUIRE_HISTORY |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_DESCRIPTION |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING,
self->cancellable,
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index b20b2e0..9d79e45 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -160,6 +160,7 @@ gs_shell_search_load (GsShellSearch *self)
self->value,
GS_PLUGIN_REFINE_FLAGS_DEFAULT |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_HISTORY |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_DESCRIPTION |
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 3c187f5..756e194 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -34,6 +34,7 @@ plugin_LTLIBRARIES = \
libgs_plugin_menu-spec-categories.la \
libgs_plugin_menu-spec-refine.la \
libgs_plugin_local-ratings.la \
+ libgs_plugin_fedora_provenance.la \
libgs_plugin_fedora_tagger_ratings.la \
libgs_plugin_fedora_tagger_usage.la \
libgs_plugin_epiphany.la \
@@ -58,6 +59,11 @@ libgs_plugin_dummy_la_LIBADD = $(GS_PLUGIN_LIBS)
libgs_plugin_dummy_la_LDFLAGS = -module -avoid-version
libgs_plugin_dummy_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+libgs_plugin_fedora_provenance_la_SOURCES = gs-plugin-fedora-provenance.c
+libgs_plugin_fedora_provenance_la_LIBADD = $(GS_PLUGIN_LIBS) $(SOUP_LIBS) $(SQLITE_LIBS)
+libgs_plugin_fedora_provenance_la_LDFLAGS = -module -avoid-version
+libgs_plugin_fedora_provenance_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+
libgs_plugin_fedora_tagger_ratings_la_SOURCES = gs-plugin-fedora-tagger-ratings.c
libgs_plugin_fedora_tagger_ratings_la_LIBADD = $(GS_PLUGIN_LIBS) $(SOUP_LIBS) $(SQLITE_LIBS)
libgs_plugin_fedora_tagger_ratings_la_LDFLAGS = -module -avoid-version
diff --git a/src/plugins/gs-plugin-fedora-provenance.c b/src/plugins/gs-plugin-fedora-provenance.c
new file mode 100644
index 0000000..7d87580
--- /dev/null
+++ b/src/plugins/gs-plugin-fedora-provenance.c
@@ -0,0 +1,135 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <gs-plugin.h>
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+ return "fedora-provenance";
+}
+
+/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+ /* check that we are running on Fedora */
+ if (!gs_plugin_check_distro_id (plugin, "fedora")) {
+ gs_plugin_set_enabled (plugin, FALSE);
+ g_debug ("disabling '%s' as we're not Fedora", plugin->name);
+ return;
+ }
+}
+
+/**
+ * gs_plugin_get_deps:
+ */
+const gchar **
+gs_plugin_get_deps (GsPlugin *plugin)
+{
+ static const gchar *deps[] = {
+ "packagekit-refine", /* after the package source is set */
+ NULL };
+ return deps;
+}
+
+/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+}
+
+/**
+ * gs_plugin_fedora_provenance_refine_app:
+ */
+static void
+gs_plugin_fedora_provenance_refine_app (GsApp *app)
+{
+ const gchar *origin;
+ guint i;
+ const gchar *valid[] = { "fedora",
+ "fedora-debuginfo",
+ "fedora-source",
+ "koji-override-0",
+ "koji-override-1",
+ "rawhide",
+ "rawhide-debuginfo",
+ "rawhide-source",
+ "updates",
+ "updates-debuginfo",
+ "updates-source",
+ "updates-testing",
+ "updates-testing-debuginfo",
+ "updates-testing-source",
+ NULL };
+
+ /* this only works for packages */
+ origin = gs_app_get_source_id_default (app);
+ if (origin == NULL)
+ return;
+ origin = g_strrstr (origin, ";");
+ if (origin == NULL)
+ return;
+ if (g_str_has_prefix (origin + 1, "installed:"))
+ origin += 10;
+ for (i = 0; valid[i] != NULL; i++) {
+ if (g_strcmp0 (origin + 1, valid[i]) == 0) {
+ gs_app_set_provenance (app, TRUE);
+ break;
+ }
+ }
+}
+
+/**
+ * gs_plugin_refine:
+ */
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GList **list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GList *l;
+ GsApp *app;
+
+ /* not required */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
+ return TRUE;
+
+ /* refine apps */
+ for (l = *list; l != NULL; l = l->next) {
+ app = GS_APP (l->data);
+ if (gs_app_get_provenance (app))
+ continue;
+ gs_plugin_fedora_provenance_refine_app (app);
+ }
+ return TRUE;
+}
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 8ed3195..24a093c 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -796,6 +796,8 @@ gs_plugin_refine_requires_package_id (GsApp *app, GsPluginRefineFlags flags)
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;
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]