From 4903fe100d2fcdda977a3375a454fda7f8b1ccdb Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 5 Feb 2015 22:50:38 +0100 Subject: [PATCH] Remove unused removed dirs after install/uninstall --- xdg-app-builtins-install.c | 4 +++ xdg-app-builtins-uninstall.c | 4 +++ xdg-app-dir.c | 48 ++++++++++++++++++++++++++++++++++++ xdg-app-dir.h | 3 +++ 4 files changed, 59 insertions(+) diff --git a/xdg-app-builtins-install.c b/xdg-app-builtins-install.c index bc9671a8..f915b4d9 100644 --- a/xdg-app-builtins-install.c +++ b/xdg-app-builtins-install.c @@ -72,6 +72,8 @@ xdg_app_builtin_install_runtime (int argc, char **argv, GCancellable *cancellabl if (!xdg_app_dir_deploy (dir, ref, NULL, cancellable, error)) goto out; + xdg_app_dir_cleanup_removed (dir, cancellable, NULL); + ret = TRUE; out: @@ -138,6 +140,8 @@ xdg_app_builtin_install_app (int argc, char **argv, GCancellable *cancellable, G if (!xdg_app_dir_deploy (dir, ref, NULL, cancellable, error)) goto out; + xdg_app_dir_cleanup_removed (dir, cancellable, NULL); + ret = TRUE; out: diff --git a/xdg-app-builtins-uninstall.c b/xdg-app-builtins-uninstall.c index b1b9cc1c..c2fd676a 100644 --- a/xdg-app-builtins-uninstall.c +++ b/xdg-app-builtins-uninstall.c @@ -159,6 +159,8 @@ xdg_app_builtin_uninstall_runtime (int argc, char **argv, GCancellable *cancella goto out; } + xdg_app_dir_cleanup_removed (dir, cancellable, NULL); + ret = TRUE; out: @@ -269,6 +271,8 @@ xdg_app_builtin_uninstall_app (int argc, char **argv, GCancellable *cancellable, goto out; } + xdg_app_dir_cleanup_removed (dir, cancellable, NULL); + ret = TRUE; out: diff --git a/xdg-app-dir.c b/xdg-app-dir.c index 2203bf22..1a7260c3 100644 --- a/xdg-app-dir.c +++ b/xdg-app-dir.c @@ -1111,6 +1111,54 @@ xdg_app_dir_undeploy (XdgAppDir *self, return ret; } +gboolean +xdg_app_dir_cleanup_removed (XdgAppDir *self, + GCancellable *cancellable, + GError **error) +{ + gboolean ret = FALSE; + gs_unref_object GFile *removed_dir = NULL; + gs_unref_object GFileEnumerator *dir_enum = NULL; + gs_unref_object GFileInfo *child_info = NULL; + GError *temp_error = NULL; + + removed_dir = xdg_app_dir_get_removed_dir (self); + if (!g_file_query_exists (removed_dir, cancellable)) + return TRUE; + + dir_enum = g_file_enumerate_children (removed_dir, OSTREE_GIO_FAST_QUERYINFO, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + cancellable, + error); + if (!dir_enum) + goto out; + + while ((child_info = g_file_enumerator_next_file (dir_enum, cancellable, &temp_error)) != NULL) + { + const char *name = g_file_info_get_name (child_info); + gs_unref_object GFile *child = g_file_get_child (removed_dir, name); + + if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY && + !dir_is_locked (child)) + { + gs_shutil_rm_rf (child, cancellable, NULL); + } + + g_clear_object (&child_info); + } + + if (temp_error != NULL) + { + g_propagate_error (error, temp_error); + goto out; + } + + ret = TRUE; + out: + return ret; +} + + gboolean xdg_app_dir_prune (XdgAppDir *self, GCancellable *cancellable, diff --git a/xdg-app-dir.h b/xdg-app-dir.h index 376bd326..942b7f15 100644 --- a/xdg-app-dir.h +++ b/xdg-app-dir.h @@ -79,6 +79,9 @@ gboolean xdg_app_dir_undeploy (XdgAppDir *self, gboolean xdg_app_dir_prune (XdgAppDir *self, GCancellable *cancellable, GError **error); +gboolean xdg_app_dir_cleanup_removed (XdgAppDir *self, + GCancellable *cancellable, + GError **error); gboolean xdg_app_dir_collect_deployed_refs (XdgAppDir *self, const char *type, const char *name_prefix,