repo: Add ostree_repo_remote_get_url()

Peeking at remote details by way of ostree_repo_copy_config() doesn't
work anymore.
This commit is contained in:
Matthew Barnes 2014-12-03 19:46:03 -05:00
parent 17b9e399b8
commit f79896693e
3 changed files with 47 additions and 9 deletions

View File

@ -701,6 +701,47 @@ ostree_repo_remote_delete (OstreeRepo *self,
return ret; return ret;
} }
/**
* ostree_repo_remote_get_url:
* @self: Repo
* @name: Name of remote
* @out_url: (out) (allow-none): Remote's URL
* @error: Error
*
* Return the URL of the remote named @name through @out_url. It is an
* error if the provided remote does not exist.
*
* Returns: %TRUE on success, %FALSE on failure
*/
gboolean
ostree_repo_remote_get_url (OstreeRepo *self,
const char *name,
char **out_url,
GError **error)
{
local_cleanup_remote OstreeRemote *remote = NULL;
gs_free char *url = NULL;
gboolean ret = FALSE;
g_return_val_if_fail (name != NULL, FALSE);
remote = ost_repo_get_remote (self, name, error);
if (remote == NULL)
goto out;
url = g_key_file_get_string (remote->options, remote->group, "url", error);
if (url != NULL)
{
gs_transfer_out_value (out_url, &url);
ret = TRUE;
}
out:
return ret;
}
static gboolean static gboolean
ostree_repo_mode_to_string (OstreeRepoMode mode, ostree_repo_mode_to_string (OstreeRepoMode mode,
const char **out_mode, const char **out_mode,

View File

@ -79,6 +79,11 @@ gboolean ostree_repo_remote_delete (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
gboolean ostree_repo_remote_get_url (OstreeRepo *self,
const char *name,
char **out_url,
GError **error);
OstreeRepo * ostree_repo_get_parent (OstreeRepo *self); OstreeRepo * ostree_repo_get_parent (OstreeRepo *self);
gboolean ostree_repo_write_config (OstreeRepo *self, gboolean ostree_repo_write_config (OstreeRepo *self,

View File

@ -71,9 +71,7 @@ ostree_builtin_remote (int argc, char **argv, GCancellable *cancellable, GError
gs_unref_object OstreeRepo *repo = NULL; gs_unref_object OstreeRepo *repo = NULL;
gboolean ret = FALSE; gboolean ret = FALSE;
const char *op; const char *op;
gs_free char *key = NULL;
guint i; guint i;
GKeyFile *config = NULL;
const char *remote_name; const char *remote_name;
context = g_option_context_new ("OPERATION NAME [args] - Control remote repository configuration"); context = g_option_context_new ("OPERATION NAME [args] - Control remote repository configuration");
@ -93,9 +91,6 @@ ostree_builtin_remote (int argc, char **argv, GCancellable *cancellable, GError
op = argv[1]; op = argv[1];
remote_name = argv[2]; remote_name = argv[2];
key = g_strdup_printf ("remote \"%s\"", remote_name);
config = ostree_repo_copy_config (repo);
if (!strcmp (op, "add")) if (!strcmp (op, "add"))
{ {
@ -155,8 +150,7 @@ ostree_builtin_remote (int argc, char **argv, GCancellable *cancellable, GError
{ {
gs_free char *url = NULL; gs_free char *url = NULL;
url = g_key_file_get_string (config, key, "url", error); if (!ostree_repo_remote_get_url (repo, remote_name, &url, error))
if (url == NULL)
goto out; goto out;
g_print ("%s\n", url); g_print ("%s\n", url);
@ -176,7 +170,5 @@ ostree_builtin_remote (int argc, char **argv, GCancellable *cancellable, GError
out: out:
if (context) if (context)
g_option_context_free (context); g_option_context_free (context);
if (config)
g_key_file_free (config);
return ret; return ret;
} }