[gnome-software/1479-repositories-settings-optional-repos-can-t-be-disabled] gs-plugin-provenance: Handle also 'required-repos' key
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1479-repositories-settings-optional-repos-can-t-be-disabled] gs-plugin-provenance: Handle also 'required-repos' key
- Date: Tue, 5 Oct 2021 09:49:03 +0000 (UTC)
commit fe604b8a1106ff8c8ed7e24345429a6e2db4a785
Author: Milan Crha <mcrha redhat com>
Date: Tue Oct 5 11:46:22 2021 +0200
gs-plugin-provenance: Handle also 'required-repos' key
Let it handle also 'required-repos' settings key, beside the 'official-repos'
key, which are close enough to share the same code and memory. With this
done the repositories can be marked as compulsory, independently from the official
repositories.
Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1479
plugins/core/gs-plugin-provenance.c | 87 +++++++++++++++++++++++++++++++------
1 file changed, 73 insertions(+), 14 deletions(-)
---
diff --git a/plugins/core/gs-plugin-provenance.c b/plugins/core/gs-plugin-provenance.c
index aed28ec9a..53f613ee9 100644
--- a/plugins/core/gs-plugin-provenance.c
+++ b/plugins/core/gs-plugin-provenance.c
@@ -14,25 +14,59 @@
/*
* SECTION:
* Sets the package provenance to TRUE if installed by an official
- * software source.
+ * software source. Also sets compulsory quirk when a required repository.
*/
struct GsPluginData {
GSettings *settings;
- GHashTable *repos; /* gchar *name ~> NULL */
+ GHashTable *repos; /* gchar *name ~> guint flags */
};
+static GHashTable *
+gs_plugin_provenance_remove_by_flag (GHashTable *old_repos,
+ GsAppQuirk quirk)
+{
+ GHashTable *new_repos = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ GHashTableIter iter;
+ gpointer key, value;
+ g_hash_table_iter_init (&iter, old_repos);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ guint flags = GPOINTER_TO_UINT (value);
+ flags = flags & (~quirk);
+ if (flags != 0)
+ g_hash_table_insert (new_repos, g_strdup (key), GUINT_TO_POINTER (flags));
+ }
+ return new_repos;
+}
+
+static void
+gs_plugin_provenance_add_quirks (GsApp *app,
+ guint quirks)
+{
+ GsAppQuirk array[] = {
+ GS_APP_QUIRK_PROVENANCE,
+ GS_APP_QUIRK_COMPULSORY
+ };
+ for (guint ii = 0; ii < G_N_ELEMENTS (array); ii++) {
+ if ((quirks & array[ii]) != 0)
+ gs_app_add_quirk (app, array[ii]);
+ }
+}
+
static gchar **
-gs_plugin_provenance_get_sources (GsPlugin *plugin)
+gs_plugin_provenance_get_sources (GsPlugin *plugin,
+ const gchar *key)
{
GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *tmp;
tmp = g_getenv ("GS_SELF_TEST_PROVENANCE_SOURCES");
if (tmp != NULL) {
+ if (g_strcmp0 (key, "required-repos") == 0)
+ return NULL;
g_debug ("using custom provenance sources of %s", tmp);
return g_strsplit (tmp, ",", -1);
}
- return g_settings_get_strv (priv->settings, "official-repos");
+ return g_settings_get_strv (priv->settings, key);
}
static void
@@ -41,14 +75,26 @@ gs_plugin_provenance_settings_changed_cb (GSettings *settings,
GsPlugin *plugin)
{
GsPluginData *priv = gs_plugin_get_data (plugin);
- if (g_strcmp0 (key, "official-repos") == 0) {
+ GsAppQuirk quirk = GS_APP_QUIRK_NONE;
+
+ if (g_strcmp0 (key, "official-repos") == 0)
+ quirk = GS_APP_QUIRK_PROVENANCE;
+ else if (g_strcmp0 (key, "required-repos") == 0)
+ quirk = GS_APP_QUIRK_COMPULSORY;
+
+ if (quirk != GS_APP_QUIRK_NONE) {
/* The keys are stolen by the hash table, thus free only the array */
g_autofree gchar **repos = NULL;
- g_hash_table_remove_all (priv->repos);
- repos = gs_plugin_provenance_get_sources (plugin);
+ g_autoptr(GHashTable) old_repos = priv->repos;
+ GHashTable *new_repos = gs_plugin_provenance_remove_by_flag (old_repos, quirk);
+ repos = gs_plugin_provenance_get_sources (plugin, key);
for (guint ii = 0; repos && repos[ii]; ii++) {
- g_hash_table_insert (priv->repos, g_steal_pointer (&(repos[ii])), NULL);
+ gchar *repo = g_steal_pointer (&(repos[ii]));
+ g_hash_table_insert (new_repos, repo,
+ GUINT_TO_POINTER (quirk |
+ GPOINTER_TO_UINT (g_hash_table_lookup (new_repos, repo))));
}
+ priv->repos = new_repos;
}
}
@@ -61,6 +107,7 @@ gs_plugin_initialize (GsPlugin *plugin)
g_signal_connect (priv->settings, "changed",
G_CALLBACK (gs_plugin_provenance_settings_changed_cb), plugin);
gs_plugin_provenance_settings_changed_cb (priv->settings, "official-repos", plugin);
+ gs_plugin_provenance_settings_changed_cb (priv->settings, "required-repos", plugin);
/* after the package source is set */
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "dummy");
@@ -76,6 +123,17 @@ gs_plugin_destroy (GsPlugin *plugin)
g_object_unref (priv->settings);
}
+static gboolean
+gs_plugin_provenance_find_repo_flags (GHashTable *repos,
+ const gchar *repo,
+ guint *out_flags)
+{
+ if (repo == NULL || *repo == '\0')
+ return FALSE;
+ *out_flags = GPOINTER_TO_UINT (g_hash_table_lookup (repos, repo));
+ return *out_flags != 0;
+}
+
static gboolean
refine_app (GsPlugin *plugin,
GsApp *app,
@@ -85,6 +143,7 @@ refine_app (GsPlugin *plugin,
GError **error)
{
const gchar *origin;
+ guint quirks;
/* not required */
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
@@ -94,8 +153,8 @@ refine_app (GsPlugin *plugin,
/* simple case */
origin = gs_app_get_origin (app);
- if (origin != NULL && g_hash_table_contains (repos, origin)) {
- gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
+ if (gs_plugin_provenance_find_repo_flags (repos, origin, &quirks)) {
+ gs_plugin_provenance_add_quirks (app, quirks);
return TRUE;
}
@@ -103,9 +162,9 @@ refine_app (GsPlugin *plugin,
* provenance quirk to the system-configured repositories (but not
* user-configured ones). */
if (gs_app_get_kind (app) == AS_COMPONENT_KIND_REPOSITORY &&
- g_hash_table_contains (repos, gs_app_get_id (app))) {
+ gs_plugin_provenance_find_repo_flags (repos, gs_app_get_id (app), &quirks)) {
if (gs_app_get_scope (app) != AS_COMPONENT_SCOPE_USER)
- gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
+ gs_plugin_provenance_add_quirks (app, quirks);
return TRUE;
}
@@ -118,8 +177,8 @@ refine_app (GsPlugin *plugin,
return TRUE;
if (g_str_has_prefix (origin + 1, "installed:"))
origin += 10;
- if (g_hash_table_contains (repos, origin + 1)) {
- gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
+ if (gs_plugin_provenance_find_repo_flags (repos, origin + 1, &quirks)) {
+ gs_plugin_provenance_add_quirks (app, quirks);
return TRUE;
}
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]