|
|
017f90 |
From dca731ff0daf904911dd6815fb9a1b181329c887 Mon Sep 17 00:00:00 2001
|
|
|
017f90 |
From: Milan Crha <mcrha@redhat.com>
|
|
|
017f90 |
Date: Tue, 5 Oct 2021 11:00:20 +0200
|
|
|
017f90 |
Subject: [PATCH 1/4] gs-repo-row: Use GS_APP_QUIRK_COMPULSORY to recognize
|
|
|
017f90 |
required repositories
|
|
|
017f90 |
|
|
|
017f90 |
The GS_APP_QUIRK_PROVENANCE quirk does not mean it's also required repository,
|
|
|
017f90 |
thus use the GS_APP_QUIRK_COMPULSORY for repos, which cannot be disabled.
|
|
|
017f90 |
The GS_APP_QUIRK_PROVENANCE is used only for repositories, which cannot be removed.
|
|
|
017f90 |
---
|
|
|
017f90 |
src/gs-repo-row.c | 10 ++++++----
|
|
|
017f90 |
1 file changed, 6 insertions(+), 4 deletions(-)
|
|
|
017f90 |
|
|
|
017f90 |
diff --git a/src/gs-repo-row.c b/src/gs-repo-row.c
|
|
|
017f90 |
index 87926092f..bbf67c194 100644
|
|
|
017f90 |
--- a/src/gs-repo-row.c
|
|
|
017f90 |
+++ b/src/gs-repo-row.c
|
|
|
017f90 |
@@ -48,7 +48,8 @@ refresh_ui (GsRepoRow *row)
|
|
|
017f90 |
gboolean active = FALSE;
|
|
|
017f90 |
gboolean state_sensitive = FALSE;
|
|
|
017f90 |
gboolean busy = priv->busy_counter> 0;
|
|
|
017f90 |
- gboolean is_system_repo;
|
|
|
017f90 |
+ gboolean is_provenance;
|
|
|
017f90 |
+ gboolean is_compulsory;
|
|
|
017f90 |
|
|
|
017f90 |
if (priv->repo == NULL) {
|
|
|
017f90 |
gtk_widget_set_sensitive (priv->disable_switch, FALSE);
|
|
|
017f90 |
@@ -87,11 +88,12 @@ refresh_ui (GsRepoRow *row)
|
|
|
017f90 |
break;
|
|
|
017f90 |
}
|
|
|
017f90 |
|
|
|
017f90 |
- is_system_repo = gs_app_has_quirk (priv->repo, GS_APP_QUIRK_PROVENANCE);
|
|
|
017f90 |
+ is_provenance = gs_app_has_quirk (priv->repo, GS_APP_QUIRK_PROVENANCE);
|
|
|
017f90 |
+ is_compulsory = gs_app_has_quirk (priv->repo, GS_APP_QUIRK_COMPULSORY);
|
|
|
017f90 |
|
|
|
017f90 |
/* Disable for the system repos, if installed */
|
|
|
017f90 |
- gtk_widget_set_sensitive (priv->disable_switch, priv->supports_enable_disable && (state_sensitive || !is_system_repo || priv->always_allow_enable_disable));
|
|
|
017f90 |
- gtk_widget_set_visible (priv->remove_button, priv->supports_remove && !is_system_repo);
|
|
|
017f90 |
+ gtk_widget_set_sensitive (priv->disable_switch, priv->supports_enable_disable && (state_sensitive || !is_compulsory || priv->always_allow_enable_disable));
|
|
|
017f90 |
+ gtk_widget_set_visible (priv->remove_button, priv->supports_remove && !is_provenance && !is_compulsory);
|
|
|
017f90 |
|
|
|
017f90 |
/* Set only the 'state' to visually indicate the state is not saved yet */
|
|
|
017f90 |
if (busy)
|
|
|
017f90 |
--
|
|
|
017f90 |
GitLab
|
|
|
017f90 |
|
|
|
017f90 |
|
|
|
017f90 |
From 026218b9d3211de243dfc49eca8b8d46633882b0 Mon Sep 17 00:00:00 2001
|
|
|
017f90 |
From: Milan Crha <mcrha@redhat.com>
|
|
|
017f90 |
Date: Tue, 5 Oct 2021 11:03:31 +0200
|
|
|
017f90 |
Subject: [PATCH 2/4] gs-plugin-provenance: Improve search speed in list of
|
|
|
017f90 |
repositories
|
|
|
017f90 |
|
|
|
017f90 |
Use a GHashTable for bare repository names and a GPtrArray for those
|
|
|
017f90 |
with wildcards. This helps with speed, due to not traversing all
|
|
|
017f90 |
the repository names with the fnmatch() call.
|
|
|
017f90 |
---
|
|
|
017f90 |
plugins/core/gs-plugin-provenance.c | 55 ++++++++++++++++++++---------
|
|
|
017f90 |
1 file changed, 38 insertions(+), 17 deletions(-)
|
|
|
017f90 |
|
|
|
017f90 |
diff --git a/plugins/core/gs-plugin-provenance.c b/plugins/core/gs-plugin-provenance.c
|
|
|
017f90 |
index 97ff76798..a72c25a27 100644
|
|
|
017f90 |
--- a/plugins/core/gs-plugin-provenance.c
|
|
|
017f90 |
+++ b/plugins/core/gs-plugin-provenance.c
|
|
|
017f90 |
@@ -19,7 +19,8 @@
|
|
|
017f90 |
|
|
|
017f90 |
struct GsPluginData {
|
|
|
017f90 |
GSettings *settings;
|
|
|
017f90 |
- gchar **sources;
|
|
|
017f90 |
+ GHashTable *repos; /* gchar *name ~> NULL */
|
|
|
017f90 |
+ GPtrArray *wildcards; /* non-NULL, when have names with wildcards */
|
|
|
017f90 |
};
|
|
|
017f90 |
|
|
|
017f90 |
static gchar **
|
|
|
017f90 |
@@ -42,8 +43,24 @@ gs_plugin_provenance_settings_changed_cb (GSettings *settings,
|
|
|
017f90 |
{
|
|
|
017f90 |
GsPluginData *priv = gs_plugin_get_data (plugin);
|
|
|
017f90 |
if (g_strcmp0 (key, "official-repos") == 0) {
|
|
|
017f90 |
- g_strfreev (priv->sources);
|
|
|
017f90 |
- priv->sources = gs_plugin_provenance_get_sources (plugin);
|
|
|
017f90 |
+ /* The keys are stolen by the hash table, thus free only the array */
|
|
|
017f90 |
+ g_autofree gchar **repos = NULL;
|
|
|
017f90 |
+ g_hash_table_remove_all (priv->repos);
|
|
|
017f90 |
+ g_clear_pointer (&priv->wildcards, g_ptr_array_unref);
|
|
|
017f90 |
+ repos = gs_plugin_provenance_get_sources (plugin);
|
|
|
017f90 |
+ for (guint ii = 0; repos && repos[ii]; ii++) {
|
|
|
017f90 |
+ if (strchr (repos[ii], '*') ||
|
|
|
017f90 |
+ strchr (repos[ii], '?') ||
|
|
|
017f90 |
+ strchr (repos[ii], '[')) {
|
|
|
017f90 |
+ if (priv->wildcards == NULL)
|
|
|
017f90 |
+ priv->wildcards = g_ptr_array_new_with_free_func (g_free);
|
|
|
017f90 |
+ g_ptr_array_add (priv->wildcards, g_steal_pointer (&(repos[ii])));
|
|
|
017f90 |
+ } else {
|
|
|
017f90 |
+ g_hash_table_insert (priv->repos, g_steal_pointer (&(repos[ii])), NULL);
|
|
|
017f90 |
+ }
|
|
|
017f90 |
+ }
|
|
|
017f90 |
+ if (priv->wildcards != NULL)
|
|
|
017f90 |
+ g_ptr_array_add (priv->wildcards, NULL);
|
|
|
017f90 |
}
|
|
|
017f90 |
}
|
|
|
017f90 |
|
|
|
017f90 |
@@ -52,9 +69,10 @@ gs_plugin_initialize (GsPlugin *plugin)
|
|
|
017f90 |
{
|
|
|
017f90 |
GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
|
|
|
017f90 |
priv->settings = g_settings_new ("org.gnome.software");
|
|
|
017f90 |
+ priv->repos = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
|
|
017f90 |
g_signal_connect (priv->settings, "changed",
|
|
|
017f90 |
G_CALLBACK (gs_plugin_provenance_settings_changed_cb), plugin);
|
|
|
017f90 |
- priv->sources = gs_plugin_provenance_get_sources (plugin);
|
|
|
017f90 |
+ gs_plugin_provenance_settings_changed_cb (priv->settings, "official-repos", plugin);
|
|
|
017f90 |
|
|
|
017f90 |
/* after the package source is set */
|
|
|
017f90 |
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "dummy");
|
|
|
017f90 |
@@ -66,7 +84,8 @@ void
|
|
|
017f90 |
gs_plugin_destroy (GsPlugin *plugin)
|
|
|
017f90 |
{
|
|
|
017f90 |
GsPluginData *priv = gs_plugin_get_data (plugin);
|
|
|
017f90 |
- g_strfreev (priv->sources);
|
|
|
017f90 |
+ g_hash_table_unref (priv->repos);
|
|
|
017f90 |
+ g_clear_pointer (&priv->wildcards, g_ptr_array_unref);
|
|
|
017f90 |
g_object_unref (priv->settings);
|
|
|
017f90 |
}
|
|
|
017f90 |
|
|
|
017f90 |
@@ -74,12 +93,12 @@ static gboolean
|
|
|
017f90 |
refine_app (GsPlugin *plugin,
|
|
|
017f90 |
GsApp *app,
|
|
|
017f90 |
GsPluginRefineFlags flags,
|
|
|
017f90 |
+ GHashTable *repos,
|
|
|
017f90 |
+ GPtrArray *wildcards,
|
|
|
017f90 |
GCancellable *cancellable,
|
|
|
017f90 |
GError **error)
|
|
|
017f90 |
{
|
|
|
017f90 |
- GsPluginData *priv = gs_plugin_get_data (plugin);
|
|
|
017f90 |
const gchar *origin;
|
|
|
017f90 |
- gchar **sources;
|
|
|
017f90 |
|
|
|
017f90 |
/* not required */
|
|
|
017f90 |
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
|
|
|
017f90 |
@@ -87,14 +106,10 @@ refine_app (GsPlugin *plugin,
|
|
|
017f90 |
if (gs_app_has_quirk (app, GS_APP_QUIRK_PROVENANCE))
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
|
|
|
017f90 |
- /* nothing to search */
|
|
|
017f90 |
- sources = priv->sources;
|
|
|
017f90 |
- if (sources == NULL || sources[0] == NULL)
|
|
|
017f90 |
- return TRUE;
|
|
|
017f90 |
-
|
|
|
017f90 |
/* simple case */
|
|
|
017f90 |
origin = gs_app_get_origin (app);
|
|
|
017f90 |
- if (origin != NULL && gs_utils_strv_fnmatch (sources, origin)) {
|
|
|
017f90 |
+ if (origin != NULL && (g_hash_table_contains (repos, origin) ||
|
|
|
017f90 |
+ (wildcards != NULL && gs_utils_strv_fnmatch ((gchar **) wildcards->pdata, origin)))) {
|
|
|
017f90 |
gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
}
|
|
|
017f90 |
@@ -103,7 +118,8 @@ refine_app (GsPlugin *plugin,
|
|
|
017f90 |
* provenance quirk to the system-configured repositories (but not
|
|
|
017f90 |
* user-configured ones). */
|
|
|
017f90 |
if (gs_app_get_kind (app) == AS_COMPONENT_KIND_REPOSITORY &&
|
|
|
017f90 |
- gs_utils_strv_fnmatch (sources, gs_app_get_id (app))) {
|
|
|
017f90 |
+ (g_hash_table_contains (repos, gs_app_get_id (app)) ||
|
|
|
017f90 |
+ (wildcards != NULL && gs_utils_strv_fnmatch ((gchar **) wildcards->pdata, gs_app_get_id (app))))) {
|
|
|
017f90 |
if (gs_app_get_scope (app) != AS_COMPONENT_SCOPE_USER)
|
|
|
017f90 |
gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
@@ -118,7 +134,8 @@ refine_app (GsPlugin *plugin,
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
if (g_str_has_prefix (origin + 1, "installed:"))
|
|
|
017f90 |
origin += 10;
|
|
|
017f90 |
- if (gs_utils_strv_fnmatch (sources, origin + 1)) {
|
|
|
017f90 |
+ if (g_hash_table_contains (repos, origin + 1) ||
|
|
|
017f90 |
+ (wildcards != NULL && gs_utils_strv_fnmatch ((gchar **) wildcards->pdata, origin + 1))) {
|
|
|
017f90 |
gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
}
|
|
|
017f90 |
@@ -133,17 +150,21 @@ gs_plugin_refine (GsPlugin *plugin,
|
|
|
017f90 |
GError **error)
|
|
|
017f90 |
{
|
|
|
017f90 |
GsPluginData *priv = gs_plugin_get_data (plugin);
|
|
|
017f90 |
+ g_autoptr(GHashTable) repos = NULL;
|
|
|
017f90 |
+ g_autoptr(GPtrArray) wildcards = NULL;
|
|
|
017f90 |
|
|
|
017f90 |
/* nothing to do here */
|
|
|
017f90 |
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
+ repos = g_hash_table_ref (priv->repos);
|
|
|
017f90 |
+ wildcards = priv->wildcards != NULL ? g_ptr_array_ref (priv->wildcards) : NULL;
|
|
|
017f90 |
/* nothing to search */
|
|
|
017f90 |
- if (priv->sources == NULL || priv->sources[0] == NULL)
|
|
|
017f90 |
+ if (g_hash_table_size (repos) == 0)
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
|
|
|
017f90 |
for (guint i = 0; i < gs_app_list_length (list); i++) {
|
|
|
017f90 |
GsApp *app = gs_app_list_index (list, i);
|
|
|
017f90 |
- if (!refine_app (plugin, app, flags, cancellable, error))
|
|
|
017f90 |
+ if (!refine_app (plugin, app, flags, repos, wildcards, cancellable, error))
|
|
|
017f90 |
return FALSE;
|
|
|
017f90 |
}
|
|
|
017f90 |
|
|
|
017f90 |
--
|
|
|
017f90 |
GitLab
|
|
|
017f90 |
|
|
|
017f90 |
|
|
|
017f90 |
From b5e3356aff5fcd257248f9bb697e272c879249ae Mon Sep 17 00:00:00 2001
|
|
|
017f90 |
From: Milan Crha <mcrha@redhat.com>
|
|
|
017f90 |
Date: Tue, 5 Oct 2021 13:03:44 +0200
|
|
|
017f90 |
Subject: [PATCH 3/4] settings: Add 'required-repos' key
|
|
|
017f90 |
|
|
|
017f90 |
To be used to list repositories, which cannot be removed or disabled.
|
|
|
017f90 |
It's a complementary option for the 'official-repos' key.
|
|
|
017f90 |
---
|
|
|
017f90 |
data/org.gnome.software.gschema.xml | 4 ++++
|
|
|
017f90 |
1 file changed, 4 insertions(+)
|
|
|
017f90 |
|
|
|
017f90 |
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
|
|
|
017f90 |
index db1c27ce4..0e5706b7c 100644
|
|
|
017f90 |
--- a/data/org.gnome.software.gschema.xml
|
|
|
017f90 |
+++ b/data/org.gnome.software.gschema.xml
|
|
|
017f90 |
@@ -94,6 +94,10 @@
|
|
|
017f90 |
<default>[]</default>
|
|
|
017f90 |
<summary>A list of official repositories that should not be considered 3rd party</summary>
|
|
|
017f90 |
</key>
|
|
|
017f90 |
+ <key name="required-repos" type="as">
|
|
|
017f90 |
+ <default>[]</default>
|
|
|
017f90 |
+ <summary>A list of required repositories that cannot be disabled or removed</summary>
|
|
|
017f90 |
+ </key>
|
|
|
017f90 |
<key name="free-repos" type="as">
|
|
|
017f90 |
<default>[]</default>
|
|
|
017f90 |
<summary>A list of official repositories that should be considered free software</summary>
|
|
|
017f90 |
--
|
|
|
017f90 |
GitLab
|
|
|
017f90 |
|
|
|
017f90 |
|
|
|
017f90 |
From d6b8b206a596bb520a0b77066898b44a5ef18920 Mon Sep 17 00:00:00 2001
|
|
|
017f90 |
From: Milan Crha <mcrha@redhat.com>
|
|
|
017f90 |
Date: Tue, 5 Oct 2021 14:16:56 +0200
|
|
|
017f90 |
Subject: [PATCH 4/4] gs-plugin-provenance: Handle also 'required-repos' key
|
|
|
017f90 |
|
|
|
017f90 |
Let it handle also 'required-repos' settings key, beside the 'official-repos'
|
|
|
017f90 |
key, which are close enough to share the same code and memory. With this
|
|
|
017f90 |
done the repositories can be marked as compulsory, independently from the official
|
|
|
017f90 |
repositories.
|
|
|
017f90 |
|
|
|
017f90 |
Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1479
|
|
|
017f90 |
---
|
|
|
017f90 |
plugins/core/gs-plugin-provenance.c | 142 +++++++++++++++++++++-------
|
|
|
017f90 |
1 file changed, 108 insertions(+), 34 deletions(-)
|
|
|
017f90 |
|
|
|
017f90 |
diff --git a/plugins/core/gs-plugin-provenance.c b/plugins/core/gs-plugin-provenance.c
|
|
|
017f90 |
index a72c25a27..22f3c98e1 100644
|
|
|
017f90 |
--- a/plugins/core/gs-plugin-provenance.c
|
|
|
017f90 |
+++ b/plugins/core/gs-plugin-provenance.c
|
|
|
017f90 |
@@ -14,26 +14,61 @@
|
|
|
017f90 |
/*
|
|
|
017f90 |
* SECTION:
|
|
|
017f90 |
* Sets the package provenance to TRUE if installed by an official
|
|
|
017f90 |
- * software source.
|
|
|
017f90 |
+ * software source. Also sets compulsory quirk when a required repository.
|
|
|
017f90 |
*/
|
|
|
017f90 |
|
|
|
017f90 |
struct GsPluginData {
|
|
|
017f90 |
GSettings *settings;
|
|
|
017f90 |
- GHashTable *repos; /* gchar *name ~> NULL */
|
|
|
017f90 |
- GPtrArray *wildcards; /* non-NULL, when have names with wildcards */
|
|
|
017f90 |
+ GHashTable *repos; /* gchar *name ~> guint flags */
|
|
|
017f90 |
+ GPtrArray *provenance_wildcards; /* non-NULL, when have names with wildcards */
|
|
|
017f90 |
+ GPtrArray *compulsory_wildcards; /* non-NULL, when have names with wildcards */
|
|
|
017f90 |
};
|
|
|
017f90 |
|
|
|
017f90 |
+static GHashTable *
|
|
|
017f90 |
+gs_plugin_provenance_remove_by_flag (GHashTable *old_repos,
|
|
|
017f90 |
+ GsAppQuirk quirk)
|
|
|
017f90 |
+{
|
|
|
017f90 |
+ GHashTable *new_repos = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
|
|
017f90 |
+ GHashTableIter iter;
|
|
|
017f90 |
+ gpointer key, value;
|
|
|
017f90 |
+ g_hash_table_iter_init (&iter, old_repos);
|
|
|
017f90 |
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
|
|
|
017f90 |
+ guint flags = GPOINTER_TO_UINT (value);
|
|
|
017f90 |
+ flags = flags & (~quirk);
|
|
|
017f90 |
+ if (flags != 0)
|
|
|
017f90 |
+ g_hash_table_insert (new_repos, g_strdup (key), GUINT_TO_POINTER (flags));
|
|
|
017f90 |
+ }
|
|
|
017f90 |
+ return new_repos;
|
|
|
017f90 |
+}
|
|
|
017f90 |
+
|
|
|
017f90 |
+static void
|
|
|
017f90 |
+gs_plugin_provenance_add_quirks (GsApp *app,
|
|
|
017f90 |
+ guint quirks)
|
|
|
017f90 |
+{
|
|
|
017f90 |
+ GsAppQuirk array[] = {
|
|
|
017f90 |
+ GS_APP_QUIRK_PROVENANCE,
|
|
|
017f90 |
+ GS_APP_QUIRK_COMPULSORY
|
|
|
017f90 |
+ };
|
|
|
017f90 |
+ for (guint ii = 0; ii < G_N_ELEMENTS (array); ii++) {
|
|
|
017f90 |
+ if ((quirks & array[ii]) != 0)
|
|
|
017f90 |
+ gs_app_add_quirk (app, array[ii]);
|
|
|
017f90 |
+ }
|
|
|
017f90 |
+}
|
|
|
017f90 |
+
|
|
|
017f90 |
static gchar **
|
|
|
017f90 |
-gs_plugin_provenance_get_sources (GsPlugin *plugin)
|
|
|
017f90 |
+gs_plugin_provenance_get_sources (GsPlugin *plugin,
|
|
|
017f90 |
+ const gchar *key)
|
|
|
017f90 |
{
|
|
|
017f90 |
GsPluginData *priv = gs_plugin_get_data (plugin);
|
|
|
017f90 |
const gchar *tmp;
|
|
|
017f90 |
tmp = g_getenv ("GS_SELF_TEST_PROVENANCE_SOURCES");
|
|
|
017f90 |
if (tmp != NULL) {
|
|
|
017f90 |
+ if (g_strcmp0 (key, "required-repos") == 0)
|
|
|
017f90 |
+ return NULL;
|
|
|
017f90 |
g_debug ("using custom provenance sources of %s", tmp);
|
|
|
017f90 |
return g_strsplit (tmp, ",", -1);
|
|
|
017f90 |
}
|
|
|
017f90 |
- return g_settings_get_strv (priv->settings, "official-repos");
|
|
|
017f90 |
+ return g_settings_get_strv (priv->settings, key);
|
|
|
017f90 |
}
|
|
|
017f90 |
|
|
|
017f90 |
static void
|
|
|
017f90 |
@@ -42,25 +77,43 @@ gs_plugin_provenance_settings_changed_cb (GSettings *settings,
|
|
|
017f90 |
GsPlugin *plugin)
|
|
|
017f90 |
{
|
|
|
017f90 |
GsPluginData *priv = gs_plugin_get_data (plugin);
|
|
|
017f90 |
+ GsAppQuirk quirk = GS_APP_QUIRK_NONE;
|
|
|
017f90 |
+ GPtrArray **pwildcards = NULL;
|
|
|
017f90 |
+
|
|
|
017f90 |
if (g_strcmp0 (key, "official-repos") == 0) {
|
|
|
017f90 |
+ quirk = GS_APP_QUIRK_PROVENANCE;
|
|
|
017f90 |
+ pwildcards = &priv->provenance_wildcards;
|
|
|
017f90 |
+ } else if (g_strcmp0 (key, "required-repos") == 0) {
|
|
|
017f90 |
+ quirk = GS_APP_QUIRK_COMPULSORY;
|
|
|
017f90 |
+ pwildcards = &priv->compulsory_wildcards;
|
|
|
017f90 |
+ }
|
|
|
017f90 |
+
|
|
|
017f90 |
+ if (quirk != GS_APP_QUIRK_NONE) {
|
|
|
017f90 |
/* The keys are stolen by the hash table, thus free only the array */
|
|
|
017f90 |
g_autofree gchar **repos = NULL;
|
|
|
017f90 |
- g_hash_table_remove_all (priv->repos);
|
|
|
017f90 |
- g_clear_pointer (&priv->wildcards, g_ptr_array_unref);
|
|
|
017f90 |
- repos = gs_plugin_provenance_get_sources (plugin);
|
|
|
017f90 |
+ g_autoptr(GHashTable) old_repos = priv->repos;
|
|
|
017f90 |
+ g_autoptr(GPtrArray) old_wildcards = *pwildcards;
|
|
|
017f90 |
+ GHashTable *new_repos = gs_plugin_provenance_remove_by_flag (old_repos, quirk);
|
|
|
017f90 |
+ GPtrArray *new_wildcards = NULL;
|
|
|
017f90 |
+ repos = gs_plugin_provenance_get_sources (plugin, key);
|
|
|
017f90 |
for (guint ii = 0; repos && repos[ii]; ii++) {
|
|
|
017f90 |
- if (strchr (repos[ii], '*') ||
|
|
|
017f90 |
- strchr (repos[ii], '?') ||
|
|
|
017f90 |
- strchr (repos[ii], '[')) {
|
|
|
017f90 |
- if (priv->wildcards == NULL)
|
|
|
017f90 |
- priv->wildcards = g_ptr_array_new_with_free_func (g_free);
|
|
|
017f90 |
- g_ptr_array_add (priv->wildcards, g_steal_pointer (&(repos[ii])));
|
|
|
017f90 |
+ gchar *repo = g_steal_pointer (&(repos[ii]));
|
|
|
017f90 |
+ if (strchr (repo, '*') ||
|
|
|
017f90 |
+ strchr (repo, '?') ||
|
|
|
017f90 |
+ strchr (repo, '[')) {
|
|
|
017f90 |
+ if (new_wildcards == NULL)
|
|
|
017f90 |
+ new_wildcards = g_ptr_array_new_with_free_func (g_free);
|
|
|
017f90 |
+ g_ptr_array_add (new_wildcards, repo);
|
|
|
017f90 |
} else {
|
|
|
017f90 |
- g_hash_table_insert (priv->repos, g_steal_pointer (&(repos[ii])), NULL);
|
|
|
017f90 |
+ g_hash_table_insert (new_repos, repo,
|
|
|
017f90 |
+ GUINT_TO_POINTER (quirk |
|
|
|
017f90 |
+ GPOINTER_TO_UINT (g_hash_table_lookup (new_repos, repo))));
|
|
|
017f90 |
}
|
|
|
017f90 |
}
|
|
|
017f90 |
- if (priv->wildcards != NULL)
|
|
|
017f90 |
- g_ptr_array_add (priv->wildcards, NULL);
|
|
|
017f90 |
+ if (new_wildcards != NULL)
|
|
|
017f90 |
+ g_ptr_array_add (new_wildcards, NULL);
|
|
|
017f90 |
+ priv->repos = new_repos;
|
|
|
017f90 |
+ *pwildcards = new_wildcards;
|
|
|
017f90 |
}
|
|
|
017f90 |
}
|
|
|
017f90 |
|
|
|
017f90 |
@@ -73,6 +126,7 @@ gs_plugin_initialize (GsPlugin *plugin)
|
|
|
017f90 |
g_signal_connect (priv->settings, "changed",
|
|
|
017f90 |
G_CALLBACK (gs_plugin_provenance_settings_changed_cb), plugin);
|
|
|
017f90 |
gs_plugin_provenance_settings_changed_cb (priv->settings, "official-repos", plugin);
|
|
|
017f90 |
+ gs_plugin_provenance_settings_changed_cb (priv->settings, "required-repos", plugin);
|
|
|
017f90 |
|
|
|
017f90 |
/* after the package source is set */
|
|
|
017f90 |
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "dummy");
|
|
|
017f90 |
@@ -85,20 +139,42 @@ gs_plugin_destroy (GsPlugin *plugin)
|
|
|
017f90 |
{
|
|
|
017f90 |
GsPluginData *priv = gs_plugin_get_data (plugin);
|
|
|
017f90 |
g_hash_table_unref (priv->repos);
|
|
|
017f90 |
- g_clear_pointer (&priv->wildcards, g_ptr_array_unref);
|
|
|
017f90 |
+ g_clear_pointer (&priv->provenance_wildcards, g_ptr_array_unref);
|
|
|
017f90 |
+ g_clear_pointer (&priv->compulsory_wildcards, g_ptr_array_unref);
|
|
|
017f90 |
g_object_unref (priv->settings);
|
|
|
017f90 |
}
|
|
|
017f90 |
|
|
|
017f90 |
+static gboolean
|
|
|
017f90 |
+gs_plugin_provenance_find_repo_flags (GHashTable *repos,
|
|
|
017f90 |
+ GPtrArray *provenance_wildcards,
|
|
|
017f90 |
+ GPtrArray *compulsory_wildcards,
|
|
|
017f90 |
+ const gchar *repo,
|
|
|
017f90 |
+ guint *out_flags)
|
|
|
017f90 |
+{
|
|
|
017f90 |
+ if (repo == NULL || *repo == '\0')
|
|
|
017f90 |
+ return FALSE;
|
|
|
017f90 |
+ *out_flags = GPOINTER_TO_UINT (g_hash_table_lookup (repos, repo));
|
|
|
017f90 |
+ if (provenance_wildcards != NULL &&
|
|
|
017f90 |
+ gs_utils_strv_fnmatch ((gchar **) provenance_wildcards->pdata, repo))
|
|
|
017f90 |
+ *out_flags |= GS_APP_QUIRK_PROVENANCE;
|
|
|
017f90 |
+ if (compulsory_wildcards != NULL &&
|
|
|
017f90 |
+ gs_utils_strv_fnmatch ((gchar **) compulsory_wildcards->pdata, repo))
|
|
|
017f90 |
+ *out_flags |= GS_APP_QUIRK_COMPULSORY;
|
|
|
017f90 |
+ return *out_flags != 0;
|
|
|
017f90 |
+}
|
|
|
017f90 |
+
|
|
|
017f90 |
static gboolean
|
|
|
017f90 |
refine_app (GsPlugin *plugin,
|
|
|
017f90 |
GsApp *app,
|
|
|
017f90 |
GsPluginRefineFlags flags,
|
|
|
017f90 |
GHashTable *repos,
|
|
|
017f90 |
- GPtrArray *wildcards,
|
|
|
017f90 |
+ GPtrArray *provenance_wildcards,
|
|
|
017f90 |
+ GPtrArray *compulsory_wildcards,
|
|
|
017f90 |
GCancellable *cancellable,
|
|
|
017f90 |
GError **error)
|
|
|
017f90 |
{
|
|
|
017f90 |
const gchar *origin;
|
|
|
017f90 |
+ guint quirks;
|
|
|
017f90 |
|
|
|
017f90 |
/* not required */
|
|
|
017f90 |
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
|
|
|
017f90 |
@@ -108,9 +184,8 @@ refine_app (GsPlugin *plugin,
|
|
|
017f90 |
|
|
|
017f90 |
/* simple case */
|
|
|
017f90 |
origin = gs_app_get_origin (app);
|
|
|
017f90 |
- if (origin != NULL && (g_hash_table_contains (repos, origin) ||
|
|
|
017f90 |
- (wildcards != NULL && gs_utils_strv_fnmatch ((gchar **) wildcards->pdata, origin)))) {
|
|
|
017f90 |
- gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
|
|
|
017f90 |
+ if (gs_plugin_provenance_find_repo_flags (repos, provenance_wildcards, compulsory_wildcards, origin, &quirks)) {
|
|
|
017f90 |
+ gs_plugin_provenance_add_quirks (app, quirks);
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
}
|
|
|
017f90 |
|
|
|
017f90 |
@@ -118,10 +193,9 @@ refine_app (GsPlugin *plugin,
|
|
|
017f90 |
* provenance quirk to the system-configured repositories (but not
|
|
|
017f90 |
* user-configured ones). */
|
|
|
017f90 |
if (gs_app_get_kind (app) == AS_COMPONENT_KIND_REPOSITORY &&
|
|
|
017f90 |
- (g_hash_table_contains (repos, gs_app_get_id (app)) ||
|
|
|
017f90 |
- (wildcards != NULL && gs_utils_strv_fnmatch ((gchar **) wildcards->pdata, gs_app_get_id (app))))) {
|
|
|
017f90 |
+ gs_plugin_provenance_find_repo_flags (repos, provenance_wildcards, compulsory_wildcards, gs_app_get_id (app), &quirks)) {
|
|
|
017f90 |
if (gs_app_get_scope (app) != AS_COMPONENT_SCOPE_USER)
|
|
|
017f90 |
- gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
|
|
|
017f90 |
+ gs_plugin_provenance_add_quirks (app, quirks);
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
}
|
|
|
017f90 |
|
|
|
017f90 |
@@ -134,11 +208,9 @@ refine_app (GsPlugin *plugin,
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
if (g_str_has_prefix (origin + 1, "installed:"))
|
|
|
017f90 |
origin += 10;
|
|
|
017f90 |
- if (g_hash_table_contains (repos, origin + 1) ||
|
|
|
017f90 |
- (wildcards != NULL && gs_utils_strv_fnmatch ((gchar **) wildcards->pdata, origin + 1))) {
|
|
|
017f90 |
- gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
|
|
|
017f90 |
- return TRUE;
|
|
|
017f90 |
- }
|
|
|
017f90 |
+ if (gs_plugin_provenance_find_repo_flags (repos, provenance_wildcards, compulsory_wildcards, origin + 1, &quirks))
|
|
|
017f90 |
+ gs_plugin_provenance_add_quirks (app, quirks);
|
|
|
017f90 |
+
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
}
|
|
|
017f90 |
|
|
|
017f90 |
@@ -151,20 +223,22 @@ gs_plugin_refine (GsPlugin *plugin,
|
|
|
017f90 |
{
|
|
|
017f90 |
GsPluginData *priv = gs_plugin_get_data (plugin);
|
|
|
017f90 |
g_autoptr(GHashTable) repos = NULL;
|
|
|
017f90 |
- g_autoptr(GPtrArray) wildcards = NULL;
|
|
|
017f90 |
+ g_autoptr(GPtrArray) provenance_wildcards = NULL;
|
|
|
017f90 |
+ g_autoptr(GPtrArray) compulsory_wildcards = NULL;
|
|
|
017f90 |
|
|
|
017f90 |
/* nothing to do here */
|
|
|
017f90 |
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
repos = g_hash_table_ref (priv->repos);
|
|
|
017f90 |
- wildcards = priv->wildcards != NULL ? g_ptr_array_ref (priv->wildcards) : NULL;
|
|
|
017f90 |
+ provenance_wildcards = priv->provenance_wildcards != NULL ? g_ptr_array_ref (priv->provenance_wildcards) : NULL;
|
|
|
017f90 |
+ compulsory_wildcards = priv->compulsory_wildcards != NULL ? g_ptr_array_ref (priv->compulsory_wildcards) : NULL;
|
|
|
017f90 |
/* nothing to search */
|
|
|
017f90 |
- if (g_hash_table_size (repos) == 0)
|
|
|
017f90 |
+ if (g_hash_table_size (repos) == 0 && provenance_wildcards == NULL && compulsory_wildcards == NULL)
|
|
|
017f90 |
return TRUE;
|
|
|
017f90 |
|
|
|
017f90 |
for (guint i = 0; i < gs_app_list_length (list); i++) {
|
|
|
017f90 |
GsApp *app = gs_app_list_index (list, i);
|
|
|
017f90 |
- if (!refine_app (plugin, app, flags, repos, wildcards, cancellable, error))
|
|
|
017f90 |
+ if (!refine_app (plugin, app, flags, repos, provenance_wildcards, compulsory_wildcards, cancellable, error))
|
|
|
017f90 |
return FALSE;
|
|
|
017f90 |
}
|
|
|
017f90 |
|
|
|
017f90 |
--
|
|
|
017f90 |
GitLab
|
|
|
017f90 |
|