mirror of
https://github.com/ostreedev/ostree.git
synced 2025-03-13 00:58:43 +03:00
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
This commit is contained in:
parent
49540f076f
commit
cdfcf09316
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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: "
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user