[ostree] repo: Add ostree_repo_remote_get_url()



commit f79896693e08cb4ced52fb84421218f9f27c95af
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Dec 3 19:46:03 2014 -0500

    repo: Add ostree_repo_remote_get_url()
    
    Peeking at remote details by way of ostree_repo_copy_config() doesn't
    work anymore.

 src/libostree/ostree-repo.c    |   41 ++++++++++++++++++++++++++++++++++++++++
 src/libostree/ostree-repo.h    |    5 ++++
 src/ostree/ot-builtin-remote.c |   10 +--------
 3 files changed, 47 insertions(+), 9 deletions(-)
---
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 26a257d..06dee3d 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -701,6 +701,47 @@ ostree_repo_remote_delete (OstreeRepo     *self,
   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
 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 9c774cb..8ba0930 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -79,6 +79,11 @@ gboolean      ostree_repo_remote_delete (OstreeRepo     *self,
                                          GCancellable   *cancellable,
                                          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);
 
 gboolean      ostree_repo_write_config (OstreeRepo *self,
diff --git a/src/ostree/ot-builtin-remote.c b/src/ostree/ot-builtin-remote.c
index 541cf76..eced150 100644
--- a/src/ostree/ot-builtin-remote.c
+++ b/src/ostree/ot-builtin-remote.c
@@ -71,9 +71,7 @@ ostree_builtin_remote (int argc, char **argv, GCancellable *cancellable, GError
   gs_unref_object OstreeRepo *repo = NULL;
   gboolean ret = FALSE;
   const char *op;
-  gs_free char *key = NULL;
   guint i;
-  GKeyFile *config = NULL;
   const char *remote_name;
 
   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];
   remote_name = argv[2];
-  key = g_strdup_printf ("remote \"%s\"", remote_name);
-
-  config = ostree_repo_copy_config (repo);
 
   if (!strcmp (op, "add"))
     {
@@ -155,8 +150,7 @@ ostree_builtin_remote (int argc, char **argv, GCancellable *cancellable, GError
     {
       gs_free char *url = NULL;
 
-      url = g_key_file_get_string (config, key, "url", error);
-      if (url == NULL)
+      if (!ostree_repo_remote_get_url (repo, remote_name, &url, error))
         goto out;
 
       g_print ("%s\n", url);
@@ -176,7 +170,5 @@ ostree_builtin_remote (int argc, char **argv, GCancellable *cancellable, GError
  out:
   if (context)
     g_option_context_free (context);
-  if (config)
-    g_key_file_free (config);
   return ret;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]