]> git.ipfire.org Git - pakfire.git/commitdiff
file: Try to be smarter and set abspath/path automatically
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 5 Sep 2022 16:03:30 +0000 (16:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 5 Sep 2022 16:03:30 +0000 (16:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c

index 2fe7195b7b4121796c5c61882c130fc306c3508a..56a85a7165da3f24c88e6ba0aebb27be0e980ff9 100644 (file)
@@ -86,20 +86,30 @@ struct pakfire_file {
 };
 
 static int pakfire_file_from_archive_entry(struct pakfire_file* file, struct archive_entry* entry) {
+       const char* path = NULL;
        const char* attr = NULL;
        const void* value = NULL;
        size_t size = 0;
        int r = 0;
 
        // Set abspath
-       r = pakfire_file_set_abspath(file, archive_entry_sourcepath(entry));
-       if (r) {
-               ERROR(file->pakfire, "Could not set abspath: %m\n");
-               goto ERROR;
+       path = archive_entry_sourcepath(entry);
+       if (path) {
+               // Make path absolute
+               path = pakfire_path_abspath(path);
+               if (!path)
+                       goto ERROR;
+
+               // Set
+               r = pakfire_file_set_abspath(file, path);
+               if (r) {
+                       ERROR(file->pakfire, "Could not set abspath: %m\n");
+                       goto ERROR;
+               }
        }
 
        // Set path
-       const char* path = archive_entry_pathname(entry);
+       path = archive_entry_pathname(entry);
        if (path) {
                // Strip any leading dots from paths
                if (pakfire_string_startswith(path, "./"))
@@ -260,19 +270,19 @@ ERROR:
        return r;
 }
 
-struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file) {
+struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file, int digest_types) {
        struct archive_entry* entry = archive_entry_new();
        if (!entry) {
                ERROR(file->pakfire, "Could not allocate archive entry: %m\n");
                return NULL;
        }
 
-       // Set path
-       archive_entry_copy_pathname(entry, pakfire_file_get_path(file));
-
        // Set source path
        archive_entry_copy_sourcepath(entry, file->abspath);
 
+       // Set path
+       archive_entry_copy_pathname(entry, pakfire_file_get_path(file));
+
        // Set links
        if (*file->hardlink)
                archive_entry_set_hardlink(entry, file->hardlink);
@@ -367,13 +377,31 @@ const char* pakfire_file_get_abspath(struct pakfire_file* file) {
 }
 
 int pakfire_file_set_abspath(struct pakfire_file* file, const char* path) {
+       int r;
+
        // Check if path is set and absolute
        if (!path || *path != '/') {
                errno = EINVAL;
                return 1;
        }
 
-       return pakfire_string_set(file->abspath, path);
+       // Store the abspath
+       r = pakfire_string_set(file->abspath, path);
+       if (r)
+               goto ERROR;
+
+       // Store path if it isn't set, yet
+       if (!*file->path) {
+               r = pakfire_file_set_path(file, path);
+               if (r)
+                       goto ERROR;
+       }
+
+       return r;
+
+ERROR:
+       ERROR(file->pakfire, "Could not set abspath '%s': %m\n", path);
+       return r;
 }
 
 PAKFIRE_EXPORT const char* pakfire_file_get_path(struct pakfire_file* file) {