added patch from mls
authorFrank Schreiner <schreiner@suse.de>
Tue, 22 Mar 2016 16:47:49 +0000 (16:47 +0000)
committerFrank Schreiner <schreiner@suse.de>
Tue, 22 Mar 2016 16:47:49 +0000 (16:47 +0000)
src/dumper_thread.c

index 3fe4c932c570249fc216270f46e26923da24ed6a..faf8cff3ef447fc50a47bcd9544c1f413a936182 100644 (file)
@@ -244,26 +244,26 @@ load_rpm(const char *fullpath,
     if (!pkg)
         goto errexit;
 
-    // cut off trailing slashes from urls e.g. media:// -> media:
-    gsize  lb_length        = strlen(location_base);
-    gchar  *t_location_base = g_malloc0(sizeof(location_base));
-    char suf[2];
-    strncpy(suf,&location_base[lb_length-2],2);
-
-    if ( g_strcmp0(suf,"//") == 0 ) {
-        t_location_base = g_strndup(location_base,lb_length-2);
+
+    if (!media_id) {
+        pkg->location_base = cr_safe_string_chunk_insert(pkg->chunk, location_base);
     } else {
-        t_location_base = g_strdup(location_base);
+        // default location_base "media:" in split mode
+        if (!location_base)
+            location_base = "media:";
+
+        // calculate location_base
+        size_t lb_length = strlen(location_base);
+        gchar *t_location_base = g_malloc0(lb_length + 32);
+        strcpy(t_location_base, location_base);
+        if (lb_length > 2 && g_strcmp0(location_base + lb_length - 3, "://") == 0)
+            lb_length -= 2;
+        sprintf(t_location_base + lb_length, "#%d", media_id);
+        pkg->location_base = cr_safe_string_chunk_insert(pkg->chunk, t_location_base);
+        g_free(t_location_base);
     }
 
-    // if --split option was given, the media_id == 0
-    if ( media_id > 0 )
-           sprintf(t_location_base,"%s#%i",t_location_base,media_id);
-
     pkg->location_href = cr_safe_string_chunk_insert(pkg->chunk, location_href);
-    pkg->location_base = cr_safe_string_chunk_insert(pkg->chunk, t_location_base);
-
-    g_free(t_location_base);
 
     // Get checksum type string
     pkg->checksum_type = cr_safe_string_chunk_insert(pkg->chunk,