From e990815da1cdb8391f5b842b9b90f3da70f3ae99 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 25 Aug 2023 17:38:36 +0000 Subject: [PATCH] compress: Make sure that paths are relative in archives 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 --- src/libpakfire/compress.c | 21 +++++++++++++++++++++ src/libpakfire/dist.c | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/libpakfire/compress.c b/src/libpakfire/compress.c index d17da9df1..d6d8641f4 100644 --- a/src/libpakfire/compress.c +++ b/src/libpakfire/compress.c @@ -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) { diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index 860c3d5af..8becc8db3 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -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); -- 2.39.5