]> git.ipfire.org Git - pakfire.git/commitdiff
xfer: Always append a / to the base URL
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 27 Jan 2025 17:36:13 +0000 (17:36 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 27 Jan 2025 17:36:13 +0000 (17:36 +0000)
When cURL merges URLs it will cut off the last part if the URL is not
terminated with /.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/xfer.c

index 32af2f579450489d83bb24727d408822d2b349bd..454c533a7bb433fdd0d5d0d768889f3ec4976371 100644 (file)
@@ -497,7 +497,21 @@ int pakfire_xfer_set_title(struct pakfire_xfer* xfer, const char* title) {
 }
 
 int pakfire_xfer_set_baseurl(struct pakfire_xfer* xfer, const char* baseurl) {
-       return pakfire_string_set(xfer->baseurl, baseurl);
+       int r;
+
+       // Store the URL
+       r = pakfire_string_set(xfer->baseurl, baseurl);
+       if (r < 0)
+               return r;
+
+       // If the URL does not end with a /, let's add it
+       if (!pakfire_string_endswith(xfer->baseurl, "/")) {
+               r = pakfire_string_append(xfer->baseurl, "/");
+               if (r < 0)
+                       return r;
+       }
+
+       return 0;
 }
 
 const char* pakfire_xfer_get_effective_url(struct pakfire_xfer* xfer) {