From: Michael Tremer Date: Tue, 18 Oct 2022 18:26:35 +0000 (+0000) Subject: file: Accept relative paths and make them absolute X-Git-Tag: 0.9.28~247 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2cc8b5f4a7ed809746aef945829550c377029e97;p=pakfire.git file: Accept relative paths and make them absolute I have no idea what new problems this will create, but let's try... Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index d059bf5ef..10d41475d 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -113,10 +113,6 @@ static int pakfire_file_from_archive_entry(struct pakfire_file* file, struct arc // Set path path = archive_entry_pathname(entry); if (path) { - // Strip any leading dots from paths - if (pakfire_string_startswith(path, "./")) - path++; - r = pakfire_file_set_path(file, path); if (r) { ERROR(file->pakfire, "Could not set path: %m\n"); @@ -554,20 +550,35 @@ PAKFIRE_EXPORT const char* pakfire_file_get_path(struct pakfire_file* file) { PAKFIRE_EXPORT int pakfire_file_set_path(struct pakfire_file* file, const char* path) { int r = 1; - // Check if path is set and absolute - if (!path || *path != '/') { + // Check if path is set + if (!path) { errno = EINVAL; goto ERROR; } - // Store path - r = pakfire_string_set(file->path, path); - if (r) - goto ERROR; + // Strip any leading dots from paths + if (pakfire_string_startswith(path, "./")) + path++; + + switch (*path) { + // Just store the path if it is absolute + case '/': + r = pakfire_string_set(file->path, path); + if (r) + goto ERROR; + break; + + // Handle relative paths + default: + r = pakfire_string_format(file->path, "/%s", path); + if (r) + goto ERROR; + break; + } // Set abspath if it isn't set, yet if (!*file->abspath) { - r = pakfire_file_set_abspath(file, path); + r = pakfire_file_set_abspath(file, file->path); if (r) goto ERROR; }