From bd7cf1af93b405cb03ff30096937965b93db6015 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 30 May 2016 16:35:50 +0200 Subject: [PATCH] install: Better check for pre-existing installation We need an actual active installation, not just the base directory. This caused a failure if the user had tried to install and app but the installation failed. After that installation failed due to it claiming to be installed, while uninstall failed due it it *not* being installed. --- app/flatpak-builtins-install.c | 7 ++++--- common/flatpak-dir.c | 23 +++++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/flatpak-builtins-install.c b/app/flatpak-builtins-install.c index 3c12b478e..b2d32b7db 100644 --- a/app/flatpak-builtins-install.c +++ b/app/flatpak-builtins-install.c @@ -205,7 +205,8 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro const char *branch = NULL; g_autofree char *ref = NULL; gboolean is_app; - g_autoptr(GFile) deploy_base = NULL; + g_autoptr(GFile) deploy_dir = NULL; + g_autoptr(GVariant) deploy_data = NULL; context = g_option_context_new ("REPOSITORY NAME [BRANCH] - Install an application or runtime"); @@ -231,8 +232,8 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro if (ref == NULL) return FALSE; - deploy_base = flatpak_dir_get_deploy_dir (dir, ref); - if (g_file_query_exists (deploy_base, NULL)) + deploy_dir = flatpak_dir_get_if_deployed (dir, ref, NULL, cancellable); + if (deploy_dir != NULL) { g_auto(GStrv) parts = flatpak_decompose_ref (ref, error); diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index b3b46874f..10780656f 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -2770,6 +2770,7 @@ flatpak_dir_deploy_install (FlatpakDir *self, { g_auto(GLnxLockFile) lock = GLNX_LOCK_FILE_INIT; g_autoptr(GFile) deploy_base = NULL; + g_autoptr(GFile) old_deploy_dir = NULL; gboolean created_deploy_base = FALSE; gboolean ret = FALSE; g_autoptr(GError) local_error = NULL; @@ -2779,22 +2780,24 @@ flatpak_dir_deploy_install (FlatpakDir *self, cancellable, error)) goto out; + old_deploy_dir = flatpak_dir_get_if_deployed (self, ref, NULL, cancellable); + if (old_deploy_dir != NULL) + { + g_set_error (error, FLATPAK_ERROR, + FLATPAK_ERROR_ALREADY_INSTALLED, + "%s branch %s already installed", + ref_parts[1], ref_parts[3]); + goto out; + } + deploy_base = flatpak_dir_get_deploy_dir (self, ref); if (!g_file_make_directory_with_parents (deploy_base, cancellable, &local_error)) { - if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS)) - { - g_set_error (error, - G_IO_ERROR, G_IO_ERROR_EXISTS, - "%s branch %s already installed", - ref_parts[1], ref_parts[3]); - } - else + if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS)) { g_propagate_error (error, g_steal_pointer (&local_error)); + goto out; } - - goto out; } /* After we create the deploy base we must goto out on errors */