[ostree] Add "ostree remote delete" and corresponding API
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] Add "ostree remote delete" and corresponding API
- Date: Fri, 17 Oct 2014 23:09:57 +0000 (UTC)
commit cdfcf09316ed61964bde950b72092a96a221493d
Author: Colin Walters <walters verbum org>
Date: Fri Oct 17 11:47:01 2014 -0400
Add "ostree remote delete" and corresponding API
For Anaconda, we have an ugly bootstrapping problem where we need to
add the remote to the repository's config, then do a pull+deploy, then
remove and re-add the config, because /etc/ostree/remotes.d doesn't
exist yet in the target system.
https://bugzilla.gnome.org/show_bug.cgi?id=738698
src/libostree/ostree-repo.c | 76 ++++++++++++++++++++++++++++++++++++++++
src/libostree/ostree-repo.h | 5 +++
src/ostree/ot-builtin-remote.c | 5 +++
tests/test-remote-add.sh | 10 +++++
4 files changed, 96 insertions(+), 0 deletions(-)
---
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index bddfbfb..4887e8d 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -474,6 +474,82 @@ ostree_repo_remote_add (OstreeRepo *self,
return ret;
}
+/**
+ * ostree_repo_remote_delete:
+ * @self: Repo
+ * @name: Name of remote
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Delete the remote named @name. It is an error if the provided
+ * remote does not exist.
+ *
+ */
+gboolean
+ostree_repo_remote_delete (OstreeRepo *self,
+ const char *name,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ gs_unref_object GFile *etc_ostree_remotes_d = g_file_new_for_path (SYSCONFDIR "/ostree/remotes.d");
+ local_cleanup_keyfile GKeyFile *target_keyfile = NULL;
+ gs_free char *section = NULL;
+ gs_unref_object GFile *target_conf = NULL;
+ gboolean is_system;
+
+ g_return_val_if_fail (name != NULL, FALSE);
+
+ if (strchr (name, '/') != NULL)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Invalid character '/' in remote name: %s",
+ name);
+ goto out;
+ }
+
+ section = g_strdup_printf ("remote \"%s\"", name);
+
+ /* Note we prefer deleting from the config if it exists there */
+ if (g_key_file_has_group (self->config, section))
+ is_system = FALSE;
+ else
+ is_system = ostree_repo_is_system (self);
+
+ if (is_system)
+ {
+ gs_free char *target_name = NULL;
+
+ target_name = g_strconcat (name, ".conf", NULL);
+ target_conf = g_file_get_child (etc_ostree_remotes_d, target_name);
+
+ if (!gs_file_unlink (target_conf, cancellable, error))
+ goto out;
+ }
+ else
+ {
+ gsize len;
+ gs_free char *data = NULL;
+
+ target_conf = g_object_ref (self->config_file);
+
+ target_keyfile = ostree_repo_copy_config (self);
+
+ if (!g_key_file_remove_group (target_keyfile, section, error))
+ goto out;
+
+ data = g_key_file_to_data (target_keyfile, &len, NULL);
+ if (!g_file_replace_contents (target_conf, data, len,
+ NULL, FALSE, 0, NULL,
+ cancellable, error))
+ goto out;
+ }
+
+ ret = TRUE;
+ out:
+ return ret;
+}
+
static gboolean
ostree_repo_mode_to_string (OstreeRepoMode mode,
const char **out_mode,
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 5ca9b3f..d924904 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -74,6 +74,11 @@ gboolean ostree_repo_remote_add (OstreeRepo *self,
GCancellable *cancellable,
GError **error);
+gboolean ostree_repo_remote_delete (OstreeRepo *self,
+ const char *name,
+ GCancellable *cancellable,
+ GError **error);
+
OstreeRepo * ostree_repo_get_parent (OstreeRepo *self);
gboolean ostree_repo_write_config (OstreeRepo *self,
diff --git a/src/ostree/ot-builtin-remote.c b/src/ostree/ot-builtin-remote.c
index 3a9c3b7..6e63a48 100644
--- a/src/ostree/ot-builtin-remote.c
+++ b/src/ostree/ot-builtin-remote.c
@@ -160,6 +160,11 @@ ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
g_print ("%s\n", url);
}
+ else if (!strcmp (op, "delete"))
+ {
+ if (!ostree_repo_remote_delete (repo, remote_name, cancellable, error))
+ goto out;
+ }
else
{
usage_error (context, "Unknown operation", error);
diff --git a/tests/test-remote-add.sh b/tests/test-remote-add.sh
index 7cd8812..65efdc1 100755
--- a/tests/test-remote-add.sh
+++ b/tests/test-remote-add.sh
@@ -32,3 +32,13 @@ echo "ok config"
$OSTREE remote add --no-gpg-verify another http://another.com/repo
assert_file_has_content $test_tmpdir/repo/config "gpg-verify=false"
echo "ok remote no gpg-verify"
+
+$OSTREE remote delete another
+echo "ok remote delete"
+
+if $OSTREE remote delete nosuchremote 2>err.txt; then
+ assert_not_reached "Deleting remote unexpectedly succeeded"
+fi
+assert_file_has_content err.txt "error: "
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]