]> git.ipfire.org Git - pakfire.git/commitdiff
file: Accept relative paths and make them absolute
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 18 Oct 2022 18:26:35 +0000 (18:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 18 Oct 2022 18:26:35 +0000 (18:26 +0000)
I have no idea what new problems this will create, but let's try...

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

index d059bf5ef3aada85f406857ac8f03fe08450e68b..10d41475d0fc69fe097650be35958bb59088fd2c 100644 (file)
@@ -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;
        }