]> git.ipfire.org Git - pakfire.git/commitdiff
compress: Make sure that paths are relative in archives
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Aug 2023 17:38:36 +0000 (17:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Aug 2023 17:38:36 +0000 (17:38 +0000)
When we write archives, we don't want them to contain leading slashes on
the filenames. However, we want to have leading slashes on the
filelists.

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

index d17da9df11e3d6865d8fdc7273c4778d24b81f36..d6d8641f42848b466798c8ca24994b1d9d434fd3 100644 (file)
@@ -691,6 +691,19 @@ static int __pakfire_extract(struct pakfire* pakfire, struct archive* a,
        // Fetch path
        const char* path = archive_entry_pathname(entry);
 
+       // Make sure we have a leading slash on the filelist
+       if (!pakfire_string_startswith(path, "/")) {
+               r = pakfire_string_format(buffer, "/%s", path);
+               if (r)
+                       goto ERROR;
+
+               // Store the new name
+               archive_entry_set_pathname(entry, buffer);
+
+               // Update the path pointer
+               path = archive_entry_pathname(entry);
+       }
+
        // Generate a file object
        r = pakfire_file_create_from_archive_entry(&file, pakfire, entry);
        if (r)
@@ -939,6 +952,14 @@ static int __pakfire_compress_entry(struct pakfire* pakfire, struct pakfire_file
        FILE* f = NULL;
        int r;
 
+       const char* path = archive_entry_pathname(entry);
+
+       // Remove any leading slahes
+       while (*path == '/')
+               path++;
+
+       archive_entry_set_pathname(entry, path);
+
        // Write the header
        r = archive_write_header(data->archive, entry);
        if (r) {
index 860c3d5aff7590c12a70e41e0b006fb398f83f31..8becc8db387de489e66180ecc8a9a1b956484d75 100644 (file)
@@ -279,7 +279,9 @@ static int pakfire_dist_add_source(struct pakfire* pakfire, struct pakfire_packa
                        return r;
        }
 
-       pakfire_string_format(archive_path, "/files/%s", filename);
+       r = pakfire_string_format(archive_path, "files/%s", filename);
+       if (r)
+               return r;
 
        // Add file to package
        return pakfire_packager_add(packager, cache_path, archive_path);