diff options
author | Alexander Larsson <alexl@redhat.com> | 2016-05-13 14:17:46 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2016-05-13 14:17:46 +0200 |
commit | 2875cdead5e52279536a72fdbf898eeb2be2c4db (patch) | |
tree | b83f522dffe3034bd31c898c0d569eff609f94fb /common | |
parent | 753cdc97fd31affabb117375fa22bd7929215e8c (diff) | |
download | xdg-app-2875cdead5e52279536a72fdbf898eeb2be2c4db.tar.gz |
remote-delete: Move to FlatpakDir and add checks for installed refs
You can't remove a remote unless you --force or there are no installs
from it.
Diffstat (limited to 'common')
-rw-r--r-- | common/flatpak-dir.c | 107 | ||||
-rw-r--r-- | common/flatpak-dir.h | 9 |
2 files changed, 76 insertions, 40 deletions
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index dcc8821..023dd23 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -921,42 +921,6 @@ flatpak_dir_remove_appstream (FlatpakDir *self, } gboolean -flatpak_dir_remove_all_refs (FlatpakDir *self, - const char *remote, - GCancellable *cancellable, - GError **error) -{ - g_autofree char *prefix = NULL; - - g_autoptr(GHashTable) refs = NULL; - GHashTableIter hash_iter; - gpointer key; - - if (!flatpak_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) && - !flatpak_dir_remove_ref (self, remote, refspec + strlen (prefix), cancellable, error)) - return FALSE; - } - - return TRUE; -} - -gboolean flatpak_dir_deploy_appstream (FlatpakDir *self, const char *remote, const char *arch, @@ -4188,6 +4152,77 @@ flatpak_dir_list_remotes (FlatpakDir *self, } gboolean +flatpak_dir_remove_remote (FlatpakDir *self, + gboolean force_remove, + const char *remote_name, + GCancellable *cancellable, + GError **error) +{ + g_autofree char *prefix = NULL; + g_autoptr(GHashTable) refs = NULL; + GHashTableIter hash_iter; + gpointer key; + + if (!flatpak_dir_ensure_repo (self, cancellable, error)) + return FALSE; + + if (!ostree_repo_list_refs (self->repo, + NULL, + &refs, + cancellable, error)) + return FALSE; + + prefix = g_strdup_printf ("%s:", remote_name); + + if (!force_remove) + { + 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)) + { + const char *unprefixed_refspec = refspec + strlen (prefix); + g_autofree char *origin = flatpak_dir_get_origin (self, unprefixed_refspec, + cancellable, NULL); + + if (g_strcmp0 (origin, remote_name) == 0) + return flatpak_fail (error, "Can't remove remote '%s' with installed ref %s (at least)", + remote_name, unprefixed_refspec); + } + } + } + + /* Remove all refs */ + 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) && + !flatpak_dir_remove_ref (self, remote_name, refspec + strlen (prefix), cancellable, error)) + return FALSE; + } + + if (!flatpak_dir_remove_appstream (self, remote_name, + cancellable, error)) + return FALSE; + + if (!ostree_repo_remote_change (self->repo, NULL, + OSTREE_REPO_REMOTE_CHANGE_DELETE, + remote_name, NULL, + NULL, + cancellable, error)) + return FALSE; + + if (!flatpak_dir_mark_changed (self, error)) + return FALSE; + + return TRUE; +} + +gboolean flatpak_dir_modify_remote (FlatpakDir *self, const char *remote_name, GKeyFile *config, diff --git a/common/flatpak-dir.h b/common/flatpak-dir.h index 4298c83..eaceee8 100644 --- a/common/flatpak-dir.h +++ b/common/flatpak-dir.h @@ -294,10 +294,6 @@ gboolean flatpak_dir_undeploy_all (FlatpakDir *self, gboolean *was_deployed_out, GCancellable *cancellable, GError **error); -gboolean flatpak_dir_remove_all_refs (FlatpakDir *self, - const char *remote, - GCancellable *cancellable, - GError **error); gboolean flatpak_dir_remove_ref (FlatpakDir *self, const char *remote_name, const char *ref, @@ -337,6 +333,11 @@ gboolean flatpak_dir_modify_remote (FlatpakDir *self, GBytes *gpg_data, GCancellable *cancellable, GError **error); +gboolean flatpak_dir_remove_remote (FlatpakDir *self, + gboolean force_remove, + const char *remote_name, + GCancellable *cancellable, + GError **error); char *flatpak_dir_get_remote_title (FlatpakDir *self, const char *remote_name); int flatpak_dir_get_remote_prio (FlatpakDir *self, |