lib/remote: Add a method to return the URL
authorJoaquim Rocha <jrocha@endlessm.com>
Fri, 24 Nov 2017 13:56:28 +0000 (14:56 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 28 Nov 2017 18:53:25 +0000 (18:53 +0000)
When using dynamic remotes (LAN and USB), we cannot use their name with
the common remote related ops (ostree_repo_remote_...) because ostree
doesn't keep this type of remotes in its internal hash table.
Unfortunately this means that we cannot access the URL of those remotes
either (in order to e.g. set the right URL for those remotes in
Flatpak).

Since the URL is actually stored in a key file that belongs to the
OstreeRemote, then we can simply allow users access to it through a
getter.

So this patch adds a method that allows to return the URL directly from
the OstreeRemote without having to go through the OstreeRepo.

The test-repo-finder-config is also updated by this patch to check if
the URL is correct.

Closes: #1353
Approved by: cgwalters

apidoc/ostree-experimental-sections.txt
src/libostree/libostree-experimental.sym
src/libostree/ostree-remote.c
src/libostree/ostree-remote.h
tests/test-repo-finder-config.c

index fc383922d1fc0ce434cb9bad15dae8ff79aa4169..60daaca5096ac076f273bb5d87ee2dfc25aced0d 100644 (file)
@@ -19,6 +19,7 @@ OstreeRemote
 ostree_remote_ref
 ostree_remote_unref
 ostree_remote_get_name
+ostree_remote_get_url
 <SUBSECTION Standard>
 ostree_remote_get_type
 </SECTION>
index 3b991c42641f79c9bb5a565c412277e128b4da65..b83ad1b0d2312bda5ed7fbd7b2118b8e787c159e 100644 (file)
@@ -93,4 +93,5 @@ global:
 LIBOSTREE_2017.14_EXPERIMENTAL {
 global:
   ostree_remote_get_type;
+  ostree_remote_get_url;
 } LIBOSTREE_2017.13_EXPERIMENTAL;
index 605a7eb9b0911f01f60827861ea44b8dae00abc6..b75640e7bbaeb7eed7e7d94273a27219798f519e 100644 (file)
@@ -180,3 +180,21 @@ ostree_remote_get_name (OstreeRemote *remote)
 
   return remote->name;
 }
+
+/**
+ * ostree_remote_get_url:
+ * @remote: an #OstreeRemote
+ *
+ * Get the URL from the remote.
+ *
+ * Returns: (transfer full): the remote's URL
+ * Since: 2017.14
+ */
+gchar *
+ostree_remote_get_url (OstreeRemote *remote)
+{
+  g_return_val_if_fail (remote != NULL, NULL);
+  g_return_val_if_fail (remote->ref_count > 0, NULL);
+
+  return g_key_file_get_string (remote->options, remote->group, "url", NULL);
+}
index 322fb96ed5daae5be747db9534962f1d03cb81db..aa9bf731c3ebff2148fbeb1b1230b79da58e2c13 100644 (file)
@@ -57,4 +57,7 @@ void ostree_remote_unref (OstreeRemote *remote);
 _OSTREE_PUBLIC
 const gchar *ostree_remote_get_name (OstreeRemote *remote);
 
+_OSTREE_PUBLIC
+gchar *ostree_remote_get_url (OstreeRemote *remote);
+
 G_END_DECLS
index 428e02eb2c67017f130540ec716a4e50a7a3f41d..7eff53d2d1096fe9944b3d2c64e1fbefcca5bb3a 100644 (file)
@@ -284,11 +284,13 @@ test_repo_finder_config_mixed_configs (Fixture       *fixture,
           g_assert_cmpuint (g_hash_table_size (result->ref_to_checksum), ==, 2);
           g_assert_true (g_hash_table_contains (result->ref_to_checksum, &ref0));
           g_assert_true (g_hash_table_contains (result->ref_to_checksum, &ref1));
+          g_assert_cmpstr (ostree_remote_get_url (result->remote), ==, collection0_uri);
         }
       else if (g_strcmp0 (ostree_remote_get_name (result->remote), "remote1") == 0)
         {
           g_assert_cmpuint (g_hash_table_size (result->ref_to_checksum), ==, 1);
           g_assert_true (g_hash_table_contains (result->ref_to_checksum, &ref3));
+          g_assert_cmpstr (ostree_remote_get_url (result->remote), ==, collection1_uri);
         }
       else
         {