[gnome-software] flatpak: Allow removing sources



commit b64a5048df97536b91eaf773f99932dd27538e62
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jul 28 13:20:59 2016 +0100

    flatpak: Allow removing sources
    
    At the moment this just marks the remote as noenumerate=true, but we'll use
    new API if/when it becomes available.
    
    See https://github.com/flatpak/flatpak/issues/211

 src/gs-self-test.c       |    9 +++++++
 src/plugins/gs-flatpak.c |   60 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 68 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 91888b0..9065062 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -754,6 +754,15 @@ gs_plugin_loader_flatpak_repo_func (GsPluginLoader *plugin_loader)
        g_assert_no_error (error);
        g_assert (app2 != NULL);
        g_assert_cmpint (gs_app_get_state (app2), ==, AS_APP_STATE_INSTALLED);
+
+       /* remove it */
+       ret = gs_plugin_loader_app_action (plugin_loader, app,
+                                          GS_PLUGIN_LOADER_ACTION_REMOVE,
+                                          NULL,
+                                          &error);
+       g_assert_no_error (error);
+       g_assert (ret);
+       g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_AVAILABLE);
 }
 
 static void
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index cca49b0..575db79 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -509,8 +509,25 @@ gs_flatpak_app_install_source (GsFlatpak *self, GsApp *app,
                       gs_plugin_get_name (self->plugin)) != 0)
                return TRUE;
 
+       /* does the remote already exist and is disabled */
+       xremote = flatpak_installation_get_remote_by_name (self->installation,
+                                                          gs_app_get_id (app),
+                                                          cancellable, NULL);
+       if (xremote != NULL) {
+               if (!flatpak_remote_get_noenumerate (xremote)) {
+                       g_set_error (error,
+                                    GS_PLUGIN_ERROR,
+                                    GS_PLUGIN_ERROR_FAILED,
+                                    "flatpak source %s already exists",
+                                    flatpak_remote_get_name (xremote));
+                       return FALSE;
+               }
+       } else {
+               xremote = flatpak_remote_new (gs_app_get_id (app));
+       }
+
        /* create a new remote */
-       xremote = flatpak_remote_new (gs_app_get_id (app));
+       flatpak_remote_set_noenumerate (xremote, FALSE);
        flatpak_remote_set_url (xremote, gs_app_get_url (app, AS_URL_KIND_HOMEPAGE));
        if (gs_app_get_summary (app) != NULL)
                flatpak_remote_set_title (xremote, gs_app_get_summary (app));
@@ -1334,6 +1351,39 @@ gs_flatpak_launch (GsFlatpak *self,
                                            error);
 }
 
+static gboolean
+gs_flatpak_app_remove_source (GsFlatpak *self,
+                             GsApp *app,
+                             GCancellable *cancellable,
+                             GError **error)
+{
+       g_autoptr(FlatpakRemote) xremote = NULL;
+
+       /* find the remote */
+       xremote = flatpak_installation_get_remote_by_name (self->installation,
+                                                          gs_app_get_id (app),
+                                                          cancellable, error);
+       if (xremote == NULL) {
+               g_prefix_error (error,
+                               "flatpak source %s not found: ",
+                               gs_app_get_id (app));
+               return FALSE;
+       }
+
+       /* we don't actually remove the source; just mark as noenumerate */
+       gs_app_set_state (app, AS_APP_STATE_REMOVING);
+       flatpak_remote_set_noenumerate (xremote, TRUE);
+       if (!flatpak_installation_modify_remote (self->installation,
+                                                xremote,
+                                                cancellable,
+                                                error)) {
+               gs_app_set_state_recover (app);
+               return FALSE;
+       }
+       gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
+       return TRUE;
+}
+
 gboolean
 gs_flatpak_app_remove (GsFlatpak *self,
                       GsApp *app,
@@ -1351,6 +1401,14 @@ gs_flatpak_app_remove (GsFlatpak *self,
                                    cancellable, error))
                return FALSE;
 
+       /* is a source */
+       if (gs_app_get_kind (app) == AS_APP_KIND_SOURCE) {
+               return gs_flatpak_app_remove_source (self,
+                                                    app,
+                                                    cancellable,
+                                                    error);
+       }
+
        /* remove */
        gs_app_set_state (app, AS_APP_STATE_REMOVING);
        if (!flatpak_installation_uninstall (self->installation,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]