[gnome-software/1166-repository-dialog-design-updates: 3/8] plugins: Implement newly added repository manipulation functions
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1166-repository-dialog-design-updates: 3/8] plugins: Implement newly added repository manipulation functions
- Date: Tue, 27 Jul 2021 14:55:00 +0000 (UTC)
commit c959f264dccaeff449f683161415b24abeee9882
Author: Milan Crha <mcrha redhat com>
Date: Tue Jul 27 15:17:23 2021 +0200
plugins: Implement newly added repository manipulation functions
plugins/flatpak/gs-flatpak.c | 25 +++-
plugins/flatpak/gs-flatpak.h | 2 +
plugins/flatpak/gs-plugin-flatpak.c | 91 +++++++++++++-
plugins/flatpak/gs-self-test.c | 62 ++++++---
plugins/fwupd/gs-plugin-fwupd.c | 54 +++++---
plugins/packagekit/gs-plugin-packagekit.c | 202 ++++++++++++++++--------------
plugins/rpm-ostree/gs-plugin-rpm-ostree.c | 56 +++++++--
7 files changed, 342 insertions(+), 150 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 7e9c571f8..570bdd0b6 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -1583,7 +1583,9 @@ gs_flatpak_create_new_remote (GsFlatpak *self,
}
gboolean
-gs_flatpak_app_install_source (GsFlatpak *self, GsApp *app,
+gs_flatpak_app_install_source (GsFlatpak *self,
+ GsApp *app,
+ gboolean is_install,
GCancellable *cancellable,
GError **error)
{
@@ -1596,6 +1598,8 @@ gs_flatpak_app_install_source (GsFlatpak *self, GsApp *app,
/* if the remote already exists, just enable it */
g_debug ("enabling existing remote %s", flatpak_remote_get_name (xremote));
flatpak_remote_set_disabled (xremote, FALSE);
+ } else if (!is_install) {
+ g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "Cannot enable flatpak remote
'%s', remote not found", gs_app_get_id (app));
} else {
/* create a new remote */
xremote = gs_flatpak_create_new_remote (self, app, cancellable, error);
@@ -3180,10 +3184,12 @@ gs_flatpak_launch (GsFlatpak *self,
gboolean
gs_flatpak_app_remove_source (GsFlatpak *self,
GsApp *app,
+ gboolean is_remove,
GCancellable *cancellable,
GError **error)
{
g_autoptr(FlatpakRemote) xremote = NULL;
+ gboolean success;
/* find the remote */
xremote = flatpak_installation_get_remote_by_name (self->installation,
@@ -3199,10 +3205,17 @@ gs_flatpak_app_remove_source (GsFlatpak *self,
/* remove */
gs_app_set_state (app, GS_APP_STATE_REMOVING);
- if (!flatpak_installation_remove_remote (self->installation,
- gs_app_get_id (app),
- cancellable,
- error)) {
+ if (is_remove) {
+ success = flatpak_installation_remove_remote (self->installation, gs_app_get_id (app),
cancellable, error);
+ } else {
+ gboolean was_disabled = flatpak_remote_get_disabled (xremote);
+ flatpak_remote_set_disabled (xremote, TRUE);
+ success = flatpak_installation_modify_remote (self->installation, xremote, cancellable,
error);
+ if (!success)
+ flatpak_remote_set_disabled (xremote, was_disabled);
+ }
+
+ if (!success) {
gs_flatpak_error_convert (error);
gs_app_set_state_recover (app);
return FALSE;
@@ -3214,7 +3227,7 @@ gs_flatpak_app_remove_source (GsFlatpak *self,
xb_silo_invalidate (self->silo);
g_rw_lock_reader_unlock (&self->silo_lock);
- gs_app_set_state (app, GS_APP_STATE_UNAVAILABLE);
+ gs_app_set_state (app, is_remove ? GS_APP_STATE_UNAVAILABLE : GS_APP_STATE_AVAILABLE);
gs_plugin_repository_changed (self->plugin, app);
diff --git a/plugins/flatpak/gs-flatpak.h b/plugins/flatpak/gs-flatpak.h
index 26a16e6f2..890d42f41 100644
--- a/plugins/flatpak/gs-flatpak.h
+++ b/plugins/flatpak/gs-flatpak.h
@@ -78,10 +78,12 @@ gboolean gs_flatpak_launch (GsFlatpak *self,
GError **error);
gboolean gs_flatpak_app_remove_source (GsFlatpak *self,
GsApp *app,
+ gboolean is_remove,
GCancellable *cancellable,
GError **error);
gboolean gs_flatpak_app_install_source (GsFlatpak *self,
GsApp *app,
+ gboolean is_install,
GCancellable *cancellable,
GError **error);
GsApp *gs_flatpak_file_to_app_ref (GsFlatpak *self,
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index f9532c370..2bcd0371d 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -865,9 +865,8 @@ gs_plugin_app_remove (GsPlugin *plugin,
if (flatpak == NULL)
return TRUE;
- /* is a source */
- if (gs_app_get_kind (app) == AS_COMPONENT_KIND_REPOSITORY)
- return gs_flatpak_app_remove_source (flatpak, app, cancellable, error);
+ /* is a source, handled by dedicated function */
+ g_return_val_if_fail (gs_app_get_kind (app) != AS_COMPONENT_KIND_REPOSITORY, FALSE);
/* build and run transaction */
transaction = _build_transaction (plugin, flatpak, cancellable, error);
@@ -979,9 +978,8 @@ gs_plugin_app_install (GsPlugin *plugin,
if (flatpak == NULL)
return TRUE;
- /* is a source */
- if (gs_app_get_kind (app) == AS_COMPONENT_KIND_REPOSITORY)
- return gs_flatpak_app_install_source (flatpak, app, cancellable, error);
+ /* is a source, handled by dedicated function */
+ g_return_val_if_fail (gs_app_get_kind (app) != AS_COMPONENT_KIND_REPOSITORY, FALSE);
/* build */
transaction = _build_transaction (plugin, flatpak, cancellable, error);
@@ -1592,3 +1590,84 @@ gs_plugin_add_recent (GsPlugin *plugin,
}
return TRUE;
}
+
+gboolean
+gs_plugin_install_repo (GsPlugin *plugin,
+ GsApp *repo,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsFlatpak *flatpak;
+
+ /* queue for install if installation needs the network */
+ if (!app_has_local_source (repo) &&
+ !gs_plugin_get_network_available (plugin)) {
+ gs_app_set_state (repo, GS_APP_STATE_QUEUED_FOR_INSTALL);
+ return TRUE;
+ }
+
+ gs_plugin_flatpak_ensure_scope (plugin, repo);
+
+ flatpak = gs_plugin_flatpak_get_handler (plugin, repo);
+ if (flatpak == NULL)
+ return TRUE;
+
+ /* is a source */
+ g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
+
+ return gs_flatpak_app_install_source (flatpak, repo, TRUE, cancellable, error);
+}
+
+gboolean
+gs_plugin_remove_repo (GsPlugin *plugin,
+ GsApp *repo,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsFlatpak *flatpak;
+
+ flatpak = gs_plugin_flatpak_get_handler (plugin, repo);
+ if (flatpak == NULL)
+ return TRUE;
+
+ /* is a source */
+ g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
+
+ return gs_flatpak_app_remove_source (flatpak, repo, TRUE, cancellable, error);
+}
+
+gboolean
+gs_plugin_enable_repo (GsPlugin *plugin,
+ GsApp *repo,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsFlatpak *flatpak;
+
+ flatpak = gs_plugin_flatpak_get_handler (plugin, repo);
+ if (flatpak == NULL)
+ return TRUE;
+
+ /* is a source */
+ g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
+
+ return gs_flatpak_app_install_source (flatpak, repo, FALSE, cancellable, error);
+}
+
+gboolean
+gs_plugin_disable_repo (GsPlugin *plugin,
+ GsApp *repo,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsFlatpak *flatpak;
+
+ flatpak = gs_plugin_flatpak_get_handler (plugin, repo);
+ if (flatpak == NULL)
+ return TRUE;
+
+ /* is a source */
+ g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
+
+ return gs_flatpak_app_remove_source (flatpak, repo, FALSE, cancellable, error);
+}
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index e17eaf385..330855c96 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -156,7 +156,7 @@ gs_plugins_flatpak_repo_func (GsPluginLoader *plugin_loader)
/* now install the remote */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL_REPO,
"app", app,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -193,9 +193,33 @@ gs_plugins_flatpak_repo_func (GsPluginLoader *plugin_loader)
g_assert_true (app2 != NULL);
g_assert_cmpint (gs_app_get_state (app2), ==, GS_APP_STATE_INSTALLED);
+ /* disable repo */
+ g_object_unref (plugin_job);
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_DISABLE_REPO,
+ "app", app,
+ NULL);
+ ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
+ gs_test_flush_main_context ();
+ g_assert_no_error (error);
+ g_assert_true (ret);
+ g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_AVAILABLE);
+ g_assert_cmpint (gs_app_get_progress (app), ==, GS_APP_PROGRESS_UNKNOWN);
+
+ /* enable repo */
+ g_object_unref (plugin_job);
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_ENABLE_REPO,
+ "app", app,
+ NULL);
+ ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
+ gs_test_flush_main_context ();
+ g_assert_no_error (error);
+ g_assert_true (ret);
+ g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_INSTALLED);
+ g_assert_cmpint (gs_app_get_progress (app), ==, GS_APP_PROGRESS_UNKNOWN);
+
/* remove it */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE_REPO,
"app", app,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -284,7 +308,7 @@ gs_plugins_flatpak_app_with_runtime_func (GsPluginLoader *plugin_loader)
gs_app_set_management_plugin (app_source, "flatpak");
gs_app_set_state (app_source, GS_APP_STATE_AVAILABLE);
gs_flatpak_app_set_repo_url (app_source, testdir_repourl);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -477,7 +501,7 @@ gs_plugins_flatpak_app_with_runtime_func (GsPluginLoader *plugin_loader)
/* remove the remote (fail, as the runtime is still installed) */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -499,7 +523,7 @@ gs_plugins_flatpak_app_with_runtime_func (GsPluginLoader *plugin_loader)
/* remove the remote */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -548,7 +572,7 @@ gs_plugins_flatpak_app_missing_runtime_func (GsPluginLoader *plugin_loader)
gs_app_set_management_plugin (app_source, "flatpak");
gs_app_set_state (app_source, GS_APP_STATE_AVAILABLE);
gs_flatpak_app_set_repo_url (app_source, testdir_repourl);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -597,7 +621,7 @@ gs_plugins_flatpak_app_missing_runtime_func (GsPluginLoader *plugin_loader)
/* remove the remote */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -772,7 +796,7 @@ gs_plugins_flatpak_runtime_repo_func (GsPluginLoader *plugin_loader)
g_assert_true (app_source != NULL);
g_assert_cmpstr (gs_app_get_unique_id (app_source), ==, "user/flatpak/*/test/*");
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -835,7 +859,7 @@ gs_plugins_flatpak_runtime_repo_redundant_func (GsPluginLoader *plugin_loader)
/* install the source manually */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL_REPO,
"app", app_src,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -933,7 +957,7 @@ gs_plugins_flatpak_runtime_repo_redundant_func (GsPluginLoader *plugin_loader)
g_assert_true (app_source != NULL);
g_assert_cmpstr (gs_app_get_unique_id (app_source), ==, "user/flatpak/*/test/*");
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -977,7 +1001,7 @@ gs_plugins_flatpak_broken_remote_func (GsPluginLoader *plugin_loader)
gs_app_set_management_plugin (app_source, "flatpak");
gs_app_set_state (app_source, GS_APP_STATE_AVAILABLE);
gs_flatpak_app_set_repo_url (app_source, "file:///wont/work");
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -1029,7 +1053,7 @@ gs_plugins_flatpak_broken_remote_func (GsPluginLoader *plugin_loader)
/* remove source */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -1077,7 +1101,7 @@ flatpak_bundle_or_ref_helper (GsPluginLoader *plugin_loader,
gs_app_set_management_plugin (app_source, "flatpak");
gs_app_set_state (app_source, GS_APP_STATE_AVAILABLE);
gs_flatpak_app_set_repo_url (app_source, testdir_repourl);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -1272,7 +1296,7 @@ flatpak_bundle_or_ref_helper (GsPluginLoader *plugin_loader,
/* remove source */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -1286,7 +1310,7 @@ flatpak_bundle_or_ref_helper (GsPluginLoader *plugin_loader,
gs_app_set_management_plugin (runtime_source, "flatpak");
gs_app_set_state (runtime_source, GS_APP_STATE_INSTALLED);
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE_REPO,
"app", runtime_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -1395,7 +1419,7 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
gs_app_set_state (app_source, GS_APP_STATE_AVAILABLE);
repo_url = g_strdup_printf ("file://%s", repo_path);
gs_flatpak_app_set_repo_url (app_source, repo_url);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -1577,7 +1601,7 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
/* remove the remote */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -1646,7 +1670,7 @@ gs_plugins_flatpak_runtime_extension_func (GsPluginLoader *plugin_loader)
gs_app_set_state (app_source, GS_APP_STATE_AVAILABLE);
repo_url = g_strdup_printf ("file://%s", repo_path);
gs_flatpak_app_set_repo_url (app_source, repo_url);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
@@ -1839,7 +1863,7 @@ gs_plugins_flatpak_runtime_extension_func (GsPluginLoader *plugin_loader)
/* remove the remote */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE_REPO,
"app", app_source,
NULL);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
diff --git a/plugins/fwupd/gs-plugin-fwupd.c b/plugins/fwupd/gs-plugin-fwupd.c
index 3ce397cac..2e1122cc4 100644
--- a/plugins/fwupd/gs-plugin-fwupd.c
+++ b/plugins/fwupd/gs-plugin-fwupd.c
@@ -970,29 +970,13 @@ gs_plugin_app_install (GsPlugin *plugin,
gs_plugin_get_name (plugin)) != 0)
return TRUE;
- /* source -> remote */
- if (gs_app_get_kind (app) == AS_COMPONENT_KIND_REPOSITORY) {
- return gs_plugin_fwupd_modify_source (plugin, app, TRUE,
- cancellable, error);
- }
+ /* source -> remote, handled by dedicated function */
+ g_return_val_if_fail (gs_app_get_kind (app) != AS_COMPONENT_KIND_REPOSITORY, FALSE);
/* firmware */
return gs_plugin_fwupd_install (plugin, app, cancellable, error);
}
-gboolean
-gs_plugin_app_remove (GsPlugin *plugin, GsApp *app,
- GCancellable *cancellable, GError **error)
-{
- /* only process this app if was created by this plugin */
- if (g_strcmp0 (gs_app_get_management_plugin (app),
- gs_plugin_get_name (plugin)) != 0)
- return TRUE;
-
- /* source -> remote */
- return gs_plugin_fwupd_modify_source (plugin, app, FALSE, cancellable, error);
-}
-
gboolean
gs_plugin_download_app (GsPlugin *plugin,
GsApp *app,
@@ -1194,3 +1178,37 @@ gs_plugin_add_sources (GsPlugin *plugin,
}
return TRUE;
}
+
+gboolean
+gs_plugin_enable_repo (GsPlugin *plugin,
+ GsApp *repo,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* only process this app if it was created by this plugin */
+ if (g_strcmp0 (gs_app_get_management_plugin (repo),
+ gs_plugin_get_name (plugin)) != 0)
+ return TRUE;
+
+ /* source -> remote */
+ g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
+
+ return gs_plugin_fwupd_modify_source (plugin, repo, TRUE, cancellable, error);
+}
+
+gboolean
+gs_plugin_disable_repo (GsPlugin *plugin,
+ GsApp *repo,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* only process this app if it was created by this plugin */
+ if (g_strcmp0 (gs_app_get_management_plugin (repo),
+ gs_plugin_get_name (plugin)) != 0)
+ return TRUE;
+
+ /* source -> remote */
+ g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
+
+ return gs_plugin_fwupd_modify_source (plugin, repo, FALSE, cancellable, error);
+}
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 56d7e2760..068bb306c 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -361,50 +361,6 @@ gs_plugin_app_origin_repo_enable (GsPlugin *plugin,
return TRUE;
}
-static gboolean
-gs_plugin_repo_enable (GsPlugin *plugin,
- GsApp *app,
- GCancellable *cancellable,
- GError **error)
-{
- GsPluginData *priv = gs_plugin_get_data (plugin);
- g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
- g_autoptr(PkResults) results = NULL;
- g_autoptr(PkError) error_code = NULL;
-
- /* do sync call */
- gs_plugin_status_update (plugin, app, GS_PLUGIN_STATUS_WAITING);
- gs_app_set_state (app, GS_APP_STATE_INSTALLING);
- gs_packagekit_helper_add_app (helper, app);
- g_mutex_lock (&priv->task_mutex);
- pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
- results = pk_client_repo_enable (PK_CLIENT (priv->task),
- gs_app_get_id (app),
- TRUE,
- cancellable,
- gs_packagekit_helper_cb, helper,
- error);
- g_mutex_unlock (&priv->task_mutex);
-
- /* pk_client_repo_enable() returns an error if the repo is already enabled. */
- if (results != NULL &&
- (error_code = pk_results_get_error_code (results)) != NULL &&
- pk_error_get_code (error_code) == PK_ERROR_ENUM_REPO_ALREADY_SET) {
- g_clear_error (error);
- } else if (!gs_plugin_packagekit_results_valid (results, error)) {
- gs_app_set_state_recover (app);
- gs_utils_error_add_origin_id (error, app);
- return FALSE;
- }
-
- /* state is known */
- gs_app_set_state (app, GS_APP_STATE_INSTALLED);
-
- gs_plugin_repository_changed (plugin, app);
-
- return TRUE;
-}
-
gboolean
gs_plugin_app_install (GsPlugin *plugin,
GsApp *app,
@@ -427,9 +383,8 @@ gs_plugin_app_install (GsPlugin *plugin,
gs_plugin_get_name (plugin)) != 0)
return TRUE;
- /* enable repo */
- if (gs_app_get_kind (app) == AS_COMPONENT_KIND_REPOSITORY)
- return gs_plugin_repo_enable (plugin, app, cancellable, error);
+ /* enable repo, handled by dedicated function */
+ g_return_val_if_fail (gs_app_get_kind (app) != AS_COMPONENT_KIND_REPOSITORY, FALSE);
/* queue for install if installation needs the network */
if (!gs_plugin_get_network_available (plugin)) {
@@ -615,50 +570,6 @@ gs_plugin_app_install (GsPlugin *plugin,
return TRUE;
}
-static gboolean
-gs_plugin_repo_disable (GsPlugin *plugin,
- GsApp *app,
- GCancellable *cancellable,
- GError **error)
-{
- GsPluginData *priv = gs_plugin_get_data (plugin);
- g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
- g_autoptr(PkResults) results = NULL;
- g_autoptr(PkError) error_code = NULL;
-
- /* do sync call */
- gs_plugin_status_update (plugin, app, GS_PLUGIN_STATUS_WAITING);
- gs_app_set_state (app, GS_APP_STATE_REMOVING);
- gs_packagekit_helper_add_app (helper, app);
- g_mutex_lock (&priv->task_mutex);
- pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
- results = pk_client_repo_enable (PK_CLIENT (priv->task),
- gs_app_get_id (app),
- FALSE,
- cancellable,
- gs_packagekit_helper_cb, helper,
- error);
- g_mutex_unlock (&priv->task_mutex);
-
- /* pk_client_repo_enable() returns an error if the repo is already enabled. */
- if (results != NULL &&
- (error_code = pk_results_get_error_code (results)) != NULL &&
- pk_error_get_code (error_code) == PK_ERROR_ENUM_REPO_ALREADY_SET) {
- g_clear_error (error);
- } else if (!gs_plugin_packagekit_results_valid (results, error)) {
- gs_app_set_state_recover (app);
- gs_utils_error_add_origin_id (error, app);
- return FALSE;
- }
-
- /* state is known */
- gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
-
- gs_plugin_repository_changed (plugin, app);
-
- return TRUE;
-}
-
gboolean
gs_plugin_app_remove (GsPlugin *plugin,
GsApp *app,
@@ -680,9 +591,8 @@ gs_plugin_app_remove (GsPlugin *plugin,
gs_plugin_get_name (plugin)) != 0)
return TRUE;
- /* disable repo */
- if (gs_app_get_kind (app) == AS_COMPONENT_KIND_REPOSITORY)
- return gs_plugin_repo_disable (plugin, app, cancellable, error);
+ /* disable repo, handled by dedicated function */
+ g_return_val_if_fail (gs_app_get_kind (app) != AS_COMPONENT_KIND_REPOSITORY, FALSE);
/* get the list of available package ids to install */
source_ids = gs_app_get_source_ids (app);
@@ -2637,3 +2547,107 @@ gs_plugin_app_upgrade_download (GsPlugin *plugin,
gs_app_set_state (app, GS_APP_STATE_UPDATABLE);
return TRUE;
}
+
+gboolean
+gs_plugin_enable_repo (GsPlugin *plugin,
+ GsApp *repo,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(PkError) error_code = NULL;
+
+ /* only process this app if was created by this plugin */
+ if (g_strcmp0 (gs_app_get_management_plugin (repo),
+ gs_plugin_get_name (plugin)) != 0)
+ return TRUE;
+
+ /* is repo */
+ g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
+
+ /* do sync call */
+ gs_plugin_status_update (plugin, repo, GS_PLUGIN_STATUS_WAITING);
+ gs_app_set_state (repo, GS_APP_STATE_INSTALLING);
+ gs_packagekit_helper_add_app (helper, repo);
+ g_mutex_lock (&priv->task_mutex);
+ pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+ results = pk_client_repo_enable (PK_CLIENT (priv->task),
+ gs_app_get_id (repo),
+ TRUE,
+ cancellable,
+ gs_packagekit_helper_cb, helper,
+ error);
+ g_mutex_unlock (&priv->task_mutex);
+
+ /* pk_client_repo_enable() returns an error if the repo is already enabled. */
+ if (results != NULL &&
+ (error_code = pk_results_get_error_code (results)) != NULL &&
+ pk_error_get_code (error_code) == PK_ERROR_ENUM_REPO_ALREADY_SET) {
+ g_clear_error (error);
+ } else if (!gs_plugin_packagekit_results_valid (results, error)) {
+ gs_app_set_state_recover (repo);
+ gs_utils_error_add_origin_id (error, repo);
+ return FALSE;
+ }
+
+ /* state is known */
+ gs_app_set_state (repo, GS_APP_STATE_INSTALLED);
+
+ gs_plugin_repository_changed (plugin, repo);
+
+ return TRUE;
+}
+
+gboolean
+gs_plugin_disable_repo (GsPlugin *plugin,
+ GsApp *repo,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(PkError) error_code = NULL;
+
+ /* only process this app if was created by this plugin */
+ if (g_strcmp0 (gs_app_get_management_plugin (repo),
+ gs_plugin_get_name (plugin)) != 0)
+ return TRUE;
+
+ /* is repo */
+ g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
+
+ /* do sync call */
+ gs_plugin_status_update (plugin, repo, GS_PLUGIN_STATUS_WAITING);
+ gs_app_set_state (repo, GS_APP_STATE_REMOVING);
+ gs_packagekit_helper_add_app (helper, repo);
+ g_mutex_lock (&priv->task_mutex);
+ pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+ results = pk_client_repo_enable (PK_CLIENT (priv->task),
+ gs_app_get_id (repo),
+ FALSE,
+ cancellable,
+ gs_packagekit_helper_cb, helper,
+ error);
+ g_mutex_unlock (&priv->task_mutex);
+
+ /* pk_client_repo_enable() returns an error if the repo is already enabled. */
+ if (results != NULL &&
+ (error_code = pk_results_get_error_code (results)) != NULL &&
+ pk_error_get_code (error_code) == PK_ERROR_ENUM_REPO_ALREADY_SET) {
+ g_clear_error (error);
+ } else if (!gs_plugin_packagekit_results_valid (results, error)) {
+ gs_app_set_state_recover (repo);
+ gs_utils_error_add_origin_id (error, repo);
+ return FALSE;
+ }
+
+ /* state is known */
+ gs_app_set_state (repo, GS_APP_STATE_AVAILABLE);
+
+ gs_plugin_repository_changed (plugin, repo);
+
+ return TRUE;
+}
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index 541b59f84..ac26448b7 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -1316,13 +1316,12 @@ gs_plugin_app_install (GsPlugin *plugin,
if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0)
return TRUE;
+ /* enable repo, handled by dedicated function */
+ g_return_val_if_fail (gs_app_get_kind (app) != AS_COMPONENT_KIND_REPOSITORY, FALSE);
+
if (!gs_rpmostree_ref_proxies (plugin, &os_proxy, &sysroot_proxy, cancellable, error))
return FALSE;
- /* enable repo */
- if (gs_app_get_kind (app) == AS_COMPONENT_KIND_REPOSITORY)
- return gs_rpmostree_repo_enable (plugin, app, TRUE, os_proxy, sysroot_proxy, cancellable,
error);
-
switch (gs_app_get_state (app)) {
case GS_APP_STATE_AVAILABLE:
if (gs_app_get_source_default (app) == NULL) {
@@ -1422,9 +1421,8 @@ gs_plugin_app_remove (GsPlugin *plugin,
if (!gs_rpmostree_ref_proxies (plugin, &os_proxy, &sysroot_proxy, cancellable, error))
return FALSE;
- /* disable repo */
- if (gs_app_get_kind (app) == AS_COMPONENT_KIND_REPOSITORY)
- return gs_rpmostree_repo_enable (plugin, app, FALSE, os_proxy, sysroot_proxy, cancellable,
error);
+ /* disable repo, handled by dedicated function */
+ g_return_val_if_fail (gs_app_get_kind (app) != AS_COMPONENT_KIND_REPOSITORY, FALSE);
gs_app_set_state (app, GS_APP_STATE_REMOVING);
tp->app = g_object_ref (app);
@@ -2153,3 +2151,47 @@ gs_plugin_add_sources (GsPlugin *plugin,
return TRUE;
}
+
+gboolean
+gs_plugin_enable_repo (GsPlugin *plugin,
+ GsApp *repo,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GsRPMOSTreeOS) os_proxy = NULL;
+ g_autoptr(GsRPMOSTreeSysroot) sysroot_proxy = NULL;
+
+ /* only process this app if it was created by this plugin */
+ if (g_strcmp0 (gs_app_get_management_plugin (repo), gs_plugin_get_name (plugin)) != 0)
+ return TRUE;
+
+ /* enable repo */
+ g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
+
+ if (!gs_rpmostree_ref_proxies (plugin, &os_proxy, &sysroot_proxy, cancellable, error))
+ return FALSE;
+
+ return gs_rpmostree_repo_enable (plugin, repo, TRUE, os_proxy, sysroot_proxy, cancellable, error);
+}
+
+gboolean
+gs_plugin_disable_repo (GsPlugin *plugin,
+ GsApp *repo,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GsRPMOSTreeOS) os_proxy = NULL;
+ g_autoptr(GsRPMOSTreeSysroot) sysroot_proxy = NULL;
+
+ /* only process this app if it was created by this plugin */
+ if (g_strcmp0 (gs_app_get_management_plugin (repo), gs_plugin_get_name (plugin)) != 0)
+ return TRUE;
+
+ /* disable repo */
+ g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
+
+ if (!gs_rpmostree_ref_proxies (plugin, &os_proxy, &sysroot_proxy, cancellable, error))
+ return FALSE;
+
+ return gs_rpmostree_repo_enable (plugin, repo, FALSE, os_proxy, sysroot_proxy, cancellable, error);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]