Blob Blame History Raw
From f67be7b6045fb4be42ad226d0054edd685d33b9f Mon Sep 17 00:00:00 2001
From: Aleš Matěj <amatej@redhat.com>
Date: Tue, 12 Feb 2019 12:59:14 +0100
Subject: [PATCH] Consistently produce valid URLs by prepending protocol. (RhBug:1632121)

---
 src/mergerepo_c.c      | 17 ++---------------
 src/xml_dump.c         |  8 ++++++++
 src/xml_dump.h         |  8 ++++++++
 src/xml_dump_primary.c |  6 ++++--
 4 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/src/mergerepo_c.c b/src/mergerepo_c.c
index 94b929c..1ae3a9b 100644
--- a/src/mergerepo_c.c
+++ b/src/mergerepo_c.c
@@ -496,17 +496,6 @@ cr_srpm_val_destroy(gpointer data)
 }
 
 
-/** Prepend protocol if necessary
- */
-static gchar *
-prepend_protocol(const gchar *url)
-{
-    if (url && *url == '/')
-        return g_strconcat("file://", url, NULL);
-    return g_strdup(url);
-}
-
-
 int
 koji_stuff_prepare(struct KojiMergedReposStuff **koji_stuff_ptr,
                    struct CmdOptions *cmd_options,
@@ -820,9 +809,7 @@ add_package(cr_Package *pkg,
     if (!list) {
         list = g_slist_prepend(list, pkg);
         if ((!pkg->location_base || *pkg->location_base == '\0') && repopath) {
-            _cleanup_free_ gchar *repopath_with_protocol = NULL;
-            repopath_with_protocol = prepend_protocol(repopath);
-            pkg->location_base = cr_safe_string_chunk_insert(pkg->chunk, repopath_with_protocol);
+            pkg->location_base = cr_safe_string_chunk_insert(pkg->chunk, repopath);
         }
         g_hash_table_insert (merged, (gpointer) pkg->name, (gpointer) list);
         return 1;
@@ -1039,7 +1026,7 @@ merge_repos(GHashTable *merged,
                     // Koji-mergerepos specific behaviour -----------
                     if (koji_stuff && koji_stuff->pkgorigins) {
                         _cleanup_free_ gchar *nvra = cr_package_nvra(pkg);
-                        _cleanup_free_ gchar *url = prepend_protocol(ml->original_url);
+                        _cleanup_free_ gchar *url = cr_prepend_protocol(ml->original_url);
 
                         cr_printf(NULL,
                                   koji_stuff->pkgorigins,
diff --git a/src/xml_dump.c b/src/xml_dump.c
index 3fbb422..7a93231 100644
--- a/src/xml_dump.c
+++ b/src/xml_dump.c
@@ -53,6 +53,14 @@ gboolean cr_hascontrollchars(const unsigned char *str)
     return FALSE;
 }
 
+gchar *
+cr_prepend_protocol(const gchar *url)
+{
+    if (url && *url == '/')
+        return g_strconcat("file://", url, NULL);
+    return g_strdup(url);
+}
+
 void
 cr_latin1_to_utf8(const unsigned char *in, unsigned char *out)
 {
diff --git a/src/xml_dump.h b/src/xml_dump.h
index 8bb11ed..4289fc2 100644
--- a/src/xml_dump.h
+++ b/src/xml_dump.h
@@ -167,6 +167,14 @@ void cr_latin1_to_utf8(const unsigned char *in,
  */
 gboolean cr_hascontrollchars(const unsigned char *str);
 
+/**
+ * Prepend protocol if necessary
+ *
+ * @param url           input url
+ * @return              output string, must be freed
+ */
+gchar *cr_prepend_protocol(const gchar *url);
+
 /** @} */
 
 #ifdef __cplusplus
diff --git a/src/xml_dump_primary.c b/src/xml_dump_primary.c
index 5695e06..1f0292b 100644
--- a/src/xml_dump_primary.c
+++ b/src/xml_dump_primary.c
@@ -30,7 +30,6 @@
 
 #define ERR_DOMAIN      CREATEREPO_C_ERROR
 
-
 typedef enum {
     PCO_TYPE_PROVIDES,
     PCO_TYPE_CONFLICTS,
@@ -279,9 +278,12 @@ cr_xml_dump_primary_base_items(xmlNodePtr root, cr_Package *package)
 
     // Write location attribute base
     if (package->location_base && package->location_base[0] != '\0') {
+        gchar *location_base_with_protocol = NULL;
+        location_base_with_protocol = cr_prepend_protocol(package->location_base);
         cr_xmlNewProp(location,
                       BAD_CAST "xml:base",
-                      BAD_CAST package->location_base);
+                      BAD_CAST location_base_with_protocol);
+        g_free(location_base_with_protocol);
     }
 
     // Write location attribute href
--
libgit2 0.27.8