mergerepo_c: Prepend protocol (file://) for URLs in pkgorigins (if --koji is used)
authorTomas Mlcoch <tmlcoch@redhat.com>
Tue, 26 May 2015 11:54:44 +0000 (13:54 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Tue, 26 May 2015 11:54:44 +0000 (13:54 +0200)
src/mergerepo_c.c

index d28e7ce1b6b62d3d68735be1ba955049d5440d2f..f6df4fc8c18ded2582a921d2d62a0dccd7faf93e 100644 (file)
@@ -496,6 +496,17 @@ 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,
@@ -810,11 +821,7 @@ add_package(cr_Package *pkg,
         list = g_slist_prepend(list, pkg);
         if ((!pkg->location_base || *pkg->location_base == '\0') && repopath) {
             _cleanup_free_ gchar *repopath_with_protocol = NULL;
-            if (*repopath == '/')
-                // Repo path is local absolute path
-                repopath_with_protocol = g_strconcat("file://", repopath, NULL);
-            else
-                repopath_with_protocol = g_strdup(repopath);
+            repopath_with_protocol = prepend_protocol(repopath);
             pkg->location_base = cr_safe_string_chunk_insert(pkg->chunk, repopath_with_protocol);
         }
         g_hash_table_insert (merged, (gpointer) pkg->name, (gpointer) list);
@@ -933,7 +940,6 @@ add_package(cr_Package *pkg,
 }
 
 
-
 long
 merge_repos(GHashTable *merged,
             GSList *repo_list,
@@ -1032,12 +1038,13 @@ merge_repos(GHashTable *merged,
                     repo_loaded_packages++;
                     // Koji-mergerepos specific behaviour -----------
                     if (koji_stuff && koji_stuff->pkgorigins) {
-                        gchar *nvra = cr_package_nvra(pkg);
+                        _cleanup_free_ gchar *nvra = cr_package_nvra(pkg);
+                        _cleanup_free_ gchar *url = prepend_protocol(ml->original_url);
+
                         cr_printf(NULL,
                                   koji_stuff->pkgorigins,
                                   "%s\t%s\n",
-                                  nvra, ml->original_url);
-                        g_free(nvra);
+                                  nvra, url);
                     }
                     // Koji-mergerepos specific behaviour - end -----
                 }