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,