From: Michael Tremer Date: Fri, 6 Oct 2023 16:21:54 +0000 (+0000) Subject: path: Correctly set and return absolute paths X-Git-Tag: 0.9.30~1526 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2d09898037ce78f282d16d13d30f2f673a805d1;p=people%2Fms%2Fpakfire.git path: Correctly set and return absolute paths Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/path.c b/src/libpakfire/path.c index 8e13cac11..dfe8c7916 100644 --- a/src/libpakfire/path.c +++ b/src/libpakfire/path.c @@ -44,6 +44,7 @@ static void pakfire_path_free_segments(struct pakfire_path* path) { // Reset the data structure path->segments = NULL; path->num_segments = 0; + path->is_absolute = 0; } static void pakfire_path_free(struct pakfire_path* path) { @@ -100,11 +101,11 @@ static int pakfire_path_import_segments(struct pakfire_path* path, const char* s // Is the path absolute? if (*s == '/') { - path->is_absolute = 1; - // If we are joining strings and the new string is absolute, // we throw away all segments. pakfire_path_free_segments(path); + + path->is_absolute = 1; } // Copy path into buffer @@ -175,14 +176,19 @@ static int pakfire_path_to_string(struct pakfire_path* path, char* buffer, const return -ENOBUFS; // Return / for empty paths - if (!path->num_segments) - return __pakfire_string_set(buffer, length, "/"); + if (!path->num_segments) { + if (path->is_absolute) + return __pakfire_string_set(buffer, length, "/"); + else + return __pakfire_string_set(buffer, length, ""); + } for (unsigned int i = 0; i < path->num_segments; i++) { s = path->segments[i]; // Add separator - *p++ = '/'; + if (i > 0 || path->is_absolute) + *p++ = '/'; // Add the segment while (*s)