From abdbb17a724112d268ebc160aa6dfaadcd94eb22 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 18 Feb 2016 12:54:40 +0100 Subject: [PATCH] Remove all appstream checkouts and mirrored refs when deleting remote --- app/xdg-app-builtins-delete-remote.c | 8 ++++ common/xdg-app-dir.c | 61 ++++++++++++++++++++++++++++ common/xdg-app-dir.h | 8 ++++ 3 files changed, 77 insertions(+) diff --git a/app/xdg-app-builtins-delete-remote.c b/app/xdg-app-builtins-delete-remote.c index e4057c88..f32a2acd 100644 --- a/app/xdg-app-builtins-delete-remote.c +++ b/app/xdg-app-builtins-delete-remote.c @@ -47,6 +47,14 @@ xdg_app_builtin_delete_remote (int argc, char **argv, GCancellable *cancellable, remote_name = argv[1]; + if (!xdg_app_dir_remove_all_refs (dir, remote_name, + cancellable, error)) + return FALSE; + + if (!xdg_app_dir_remove_appstream (dir, remote_name, + cancellable, error)) + return FALSE; + if (!ostree_repo_remote_change (xdg_app_dir_get_repo (dir), NULL, OSTREE_REPO_REMOTE_CHANGE_DELETE, remote_name, NULL, diff --git a/common/xdg-app-dir.c b/common/xdg-app-dir.c index d0306391..88b73038 100644 --- a/common/xdg-app-dir.c +++ b/common/xdg-app-dir.c @@ -593,6 +593,67 @@ xdg_app_dir_mark_changed (XdgAppDir *self, return TRUE; } +gboolean +xdg_app_dir_remove_appstream (XdgAppDir *self, + const char *remote, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(GFile) appstream_dir = NULL; + g_autoptr(GFile) remote_dir = NULL; + g_autofree char *prefix = NULL; + g_autoptr(GHashTable) refs = NULL; + + if (!xdg_app_dir_ensure_repo (self, cancellable, error)) + return FALSE; + + appstream_dir = g_file_get_child (xdg_app_dir_get_path (self), "appstream"); + remote_dir = g_file_get_child (appstream_dir, remote); + + if (g_file_query_exists (remote_dir, cancellable) && + !gs_shutil_rm_rf (remote_dir, cancellable, error)) + return FALSE; + + return TRUE; +} + +gboolean +xdg_app_dir_remove_all_refs (XdgAppDir *self, + const char *remote, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(GFile) appstream_dir = NULL; + g_autoptr(GFile) remote_dir = NULL; + g_autofree char *prefix = NULL; + g_autoptr(GHashTable) refs = NULL; + GHashTableIter hash_iter; + gpointer key; + + if (!xdg_app_dir_ensure_repo (self, cancellable, error)) + return FALSE; + + prefix = g_strdup_printf ("%s:", remote); + + if (!ostree_repo_list_refs (self->repo, + NULL, + &refs, + cancellable, error)) + return FALSE; + + g_hash_table_iter_init (&hash_iter, refs); + while (g_hash_table_iter_next (&hash_iter, &key, NULL)) + { + const char *refspec = key; + + if (g_str_has_prefix (refspec, prefix) && + !xdg_app_dir_remove_ref (self, remote, refspec + strlen (prefix), cancellable, error)) + return FALSE; + } + + return TRUE; +} + gboolean xdg_app_dir_update_appstream (XdgAppDir *self, const char *remote, diff --git a/common/xdg-app-dir.h b/common/xdg-app-dir.h index 38a61295..25063004 100644 --- a/common/xdg-app-dir.h +++ b/common/xdg-app-dir.h @@ -130,6 +130,10 @@ gboolean xdg_app_dir_ensure_repo (XdgAppDir *self, GError **error); gboolean xdg_app_dir_mark_changed (XdgAppDir *self, GError **error); +gboolean xdg_app_dir_remove_appstream(XdgAppDir *self, + const char *remote, + GCancellable *cancellable, + GError **error); gboolean xdg_app_dir_update_appstream(XdgAppDir *self, const char *remote, const char *arch, @@ -210,6 +214,10 @@ gboolean xdg_app_dir_undeploy_all (XdgAppDir *self, gboolean *was_deployed_out, GCancellable *cancellable, GError **error); +gboolean xdg_app_dir_remove_all_refs (XdgAppDir *self, + const char *remote, + GCancellable *cancellable, + GError **error); gboolean xdg_app_dir_remove_ref (XdgAppDir *self, const char *remote_name, const char *ref,