summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-05-12 17:18:14 +0200
committerAlexander Larsson <alexl@redhat.com>2016-05-12 17:18:14 +0200
commitc5e178f339e12fe06b82681e9ac233ba98559db6 (patch)
tree44ca390a41bdeaa7eec94a4e1f286da98dc5fb4d
parent712fc9fc081a5cbaf150624b0d5ce15b7ea18849 (diff)
downloadxdg-app-c5e178f339e12fe06b82681e9ac233ba98559db6.tar.gz
Use flatpak_dir_uninstall for app and lib
-rw-r--r--app/flatpak-builtins-uninstall.c65
-rw-r--r--common/flatpak-dir.c86
-rw-r--r--common/flatpak-dir.h6
-rw-r--r--lib/flatpak-installation.c68
4 files changed, 100 insertions, 125 deletions
diff --git a/app/flatpak-builtins-uninstall.c b/app/flatpak-builtins-uninstall.c
index b488922..4504954 100644
--- a/app/flatpak-builtins-uninstall.c
+++ b/app/flatpak-builtins-uninstall.c
@@ -54,11 +54,7 @@ flatpak_builtin_uninstall (int argc, char **argv, GCancellable *cancellable, GEr
const char *name = NULL;
const char *branch = NULL;
g_autofree char *ref = NULL;
- g_autofree char *repository = NULL;
- g_autofree char *current_ref = NULL;
- gboolean was_deployed;
gboolean is_app;
- g_auto(GLnxLockFile) lock = GLNX_LOCK_FILE_INIT;
context = g_option_context_new ("APP [BRANCH] - Uninstall an application");
@@ -86,62 +82,13 @@ flatpak_builtin_uninstall (int argc, char **argv, GCancellable *cancellable, GEr
/* TODO: when removing runtimes, look for apps that use it, require --force */
- if (!flatpak_dir_lock (dir, &lock,
- cancellable, error))
+ if (!flatpak_dir_uninstall (dir,
+ ref,
+ opt_keep_ref,
+ opt_force_remove,
+ cancellable,
+ error))
return FALSE;
- repository = flatpak_dir_get_origin (dir, ref, cancellable, NULL);
-
- g_debug ("dropping active ref");
- if (!flatpak_dir_set_active (dir, ref, NULL, cancellable, error))
- return FALSE;
-
- if (is_app)
- {
- current_ref = flatpak_dir_current_ref (dir, name, cancellable);
- if (current_ref != NULL && strcmp (ref, current_ref) == 0)
- {
- g_debug ("dropping current ref");
- if (!flatpak_dir_drop_current_ref (dir, name, cancellable, error))
- return FALSE;
- }
- }
-
- if (!flatpak_dir_undeploy_all (dir, ref, opt_force_remove, &was_deployed, cancellable, error))
- return FALSE;
-
- if (!opt_keep_ref)
- {
- if (!flatpak_dir_remove_ref (dir, repository, ref, cancellable, error))
- return FALSE;
- }
-
- glnx_release_lock_file (&lock);
-
- if (!opt_keep_ref)
- {
- if (!flatpak_dir_prune (dir, cancellable, error))
- return FALSE;
- }
-
- flatpak_dir_cleanup_removed (dir, cancellable, NULL);
-
- if (is_app)
- {
- if (!flatpak_dir_update_exports (dir, name, cancellable, error))
- return FALSE;
- }
-
- if (repository != NULL &&
- g_str_has_suffix (repository, "-origin") &&
- flatpak_dir_get_remote_noenumerate (dir, repository))
- ostree_repo_remote_delete (flatpak_dir_get_repo (dir), repository, NULL, NULL);
-
- if (!flatpak_dir_mark_changed (dir, error))
- return FALSE;
-
- if (!was_deployed)
- return flatpak_fail (error, "Nothing to uninstall");
-
return TRUE;
}
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c
index a50869c..482d19b 100644
--- a/common/flatpak-dir.c
+++ b/common/flatpak-dir.c
@@ -3088,7 +3088,93 @@ flatpak_dir_update (FlatpakDir *self,
return TRUE;
}
+gboolean
+flatpak_dir_uninstall (FlatpakDir *self,
+ const char *ref,
+ gboolean keep_ref,
+ gboolean force_remove,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const char *repository;
+ g_autofree char *current_ref = NULL;
+ gboolean was_deployed;
+ gboolean is_app;
+ const char *name;
+ g_auto(GStrv) parts = NULL;
+ g_auto(GLnxLockFile) lock = GLNX_LOCK_FILE_INIT;
+ g_autoptr(GVariant) deploy_data = NULL;
+ parts = flatpak_decompose_ref (ref, error);
+ if (parts == NULL)
+ return FALSE;
+ name = parts[1];
+
+ if (!flatpak_dir_lock (self, &lock,
+ cancellable, error))
+ return FALSE;
+
+ deploy_data = flatpak_dir_get_deploy_data (self, ref,
+ cancellable, error);
+ if (deploy_data == NULL)
+ return FALSE;
+
+ repository = flatpak_deploy_data_get_origin (deploy_data);
+ if (repository == NULL)
+ return FALSE;
+
+ g_debug ("dropping active ref");
+ if (!flatpak_dir_set_active (self, ref, NULL, cancellable, error))
+ return FALSE;
+
+ is_app = g_str_has_prefix (ref, "app/");
+ if (is_app)
+ {
+ current_ref = flatpak_dir_current_ref (self, name, cancellable);
+ if (g_strcmp0 (ref, current_ref) == 0)
+ {
+ g_debug ("dropping current ref");
+ if (!flatpak_dir_drop_current_ref (self, name, cancellable, error))
+ return FALSE;
+ }
+ }
+
+ if (!flatpak_dir_undeploy_all (self, ref, force_remove, &was_deployed, cancellable, error))
+ return FALSE;
+
+ if (!keep_ref &&
+ !flatpak_dir_remove_ref (self, repository, ref, cancellable, error))
+ return FALSE;
+
+ if (is_app &&
+ !flatpak_dir_update_exports (self, name, cancellable, error))
+ return FALSE;
+
+ glnx_release_lock_file (&lock);
+
+ if (repository != NULL &&
+ g_str_has_suffix (repository, "-origin") &&
+ flatpak_dir_get_remote_noenumerate (self, repository))
+ ostree_repo_remote_delete (self->repo, repository, NULL, NULL);
+
+ if (!keep_ref &&
+ !flatpak_dir_prune (self, cancellable, error))
+ return FALSE;
+
+ flatpak_dir_cleanup_removed (self, cancellable, NULL);
+
+ if (!flatpak_dir_mark_changed (self, error))
+ return FALSE;
+
+ if (!was_deployed)
+ {
+ g_set_error (error,
+ FLATPAK_ERROR, FLATPAK_ERROR_NOT_INSTALLED,
+ "%s branch %s is not installed", name, parts[3]);
+ }
+
+ return TRUE;
+}
gboolean
flatpak_dir_collect_deployed_refs (FlatpakDir *self,
diff --git a/common/flatpak-dir.h b/common/flatpak-dir.h
index 533558c..2755b3b 100644
--- a/common/flatpak-dir.h
+++ b/common/flatpak-dir.h
@@ -269,6 +269,12 @@ gboolean flatpak_dir_update (FlatpakDir *self,
OstreeAsyncProgress *progress,
GCancellable *cancellable,
GError **error);
+gboolean flatpak_dir_uninstall (FlatpakDir *self,
+ const char *ref,
+ gboolean keep_ref,
+ gboolean force_remove,
+ GCancellable *cancellable,
+ GError **error);
gboolean flatpak_dir_undeploy (FlatpakDir *self,
const char *ref,
const char *checksum,
diff --git a/lib/flatpak-installation.c b/lib/flatpak-installation.c
index c9e7201..41c0212 100644
--- a/lib/flatpak-installation.c
+++ b/lib/flatpak-installation.c
@@ -1139,13 +1139,7 @@ flatpak_installation_uninstall (FlatpakInstallation *self,
{
FlatpakInstallationPrivate *priv = flatpak_installation_get_instance_private (self);
g_autofree char *ref = NULL;
- g_autofree char *remote_name = NULL;
- g_autofree char *current_ref = NULL;
-
- g_autoptr(GFile) deploy_base = NULL;
g_autoptr(FlatpakDir) dir_clone = NULL;
- gboolean was_deployed = FALSE;
- g_auto(GLnxLockFile) lock = GLNX_LOCK_FILE_INIT;
ref = flatpak_compose_ref (kind == FLATPAK_REF_KIND_APP, name, branch, arch, error);
if (ref == NULL)
@@ -1154,68 +1148,10 @@ flatpak_installation_uninstall (FlatpakInstallation *self,
/* prune, etc are not threadsafe, so we work on a copy */
dir_clone = flatpak_dir_clone (priv->dir);
- if (!flatpak_dir_lock (dir_clone, &lock,
- cancellable, error))
- return FALSE;
-
- deploy_base = flatpak_dir_get_deploy_dir (priv->dir, ref);
- if (!g_file_query_exists (deploy_base, cancellable))
- {
- g_set_error (error,
- FLATPAK_ERROR, FLATPAK_ERROR_NOT_INSTALLED,
- "%s branch %s is not installed", name, branch ? branch : "master");
- return FALSE;
- }
-
- remote_name = flatpak_dir_get_origin (priv->dir, ref, cancellable, error);
- if (remote_name == NULL)
- return FALSE;
-
- g_debug ("dropping active ref");
- if (!flatpak_dir_set_active (dir_clone, ref, NULL, cancellable, error))
- return FALSE;
-
- if (kind == FLATPAK_REF_KIND_APP)
- {
- current_ref = flatpak_dir_current_ref (dir_clone, name, cancellable);
- if (current_ref != NULL && strcmp (ref, current_ref) == 0)
- {
- g_debug ("dropping current ref");
- if (!flatpak_dir_drop_current_ref (dir_clone, name, cancellable, error))
- return FALSE;
- }
- }
-
- if (!flatpak_dir_undeploy_all (dir_clone, ref, FALSE, &was_deployed, cancellable, error))
- return FALSE;
-
- if (!flatpak_dir_remove_ref (dir_clone, remote_name, ref, cancellable, error))
- return FALSE;
-
- glnx_release_lock_file (&lock);
-
- if (!flatpak_dir_prune (dir_clone, cancellable, error))
- return FALSE;
-
- flatpak_dir_cleanup_removed (dir_clone, cancellable, NULL);
-
- if (kind == FLATPAK_REF_KIND_APP)
- {
- if (!flatpak_dir_update_exports (dir_clone, name, cancellable, error))
- return FALSE;
- }
-
- if (!flatpak_dir_mark_changed (dir_clone, error))
+ if (!flatpak_dir_uninstall (dir_clone, ref, FALSE, FALSE,
+ cancellable, error))
return FALSE;
- if (!was_deployed)
- {
- g_set_error (error,
- FLATPAK_ERROR, FLATPAK_ERROR_NOT_INSTALLED,
- "%s branch %s is not installed", name, branch ? branch : "master");
- return FALSE;
- }
-
return TRUE;
}