Remove unused removed dirs after install/uninstall

tingping/wmclass
Alexander Larsson 2015-02-05 22:50:38 +01:00
parent 6ea2391583
commit 4903fe100d
4 changed files with 59 additions and 0 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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,

View File

@ -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,