From 2455315911a954610dc5b6025b2d1c667e86f4f9 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 15 Mar 2023 18:40:49 +0000 Subject: [PATCH] compress: Do not overwrite configuration on extraction This is somewhat experimental and I would need to think a little bit more about this. Signed-off-by: Michael Tremer --- src/libpakfire/compress.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/libpakfire/compress.c b/src/libpakfire/compress.c index 8a5d793b..88dbdab2 100644 --- a/src/libpakfire/compress.c +++ b/src/libpakfire/compress.c @@ -32,6 +32,7 @@ #include #include #include +#include #include // Read up to N bytes for analyze the magic @@ -689,25 +690,28 @@ static int __pakfire_extract(struct pakfire* pakfire, struct archive* a, // Fetch path const char* path = archive_entry_pathname(entry); + // Generate a file object + r = pakfire_file_create_from_archive_entry(&file, pakfire, entry); + if (r) + goto ERROR; + // Add entry to filelist (if requested) if (data->filelist) { - r = pakfire_file_create_from_archive_entry(&file, pakfire, entry); - if (r) - goto ERROR; - // Append the file to the list r = pakfire_filelist_add(data->filelist, file); if (r) goto ERROR; } + const int configfile = pakfire_file_has_flag(file, PAKFIRE_FILE_CONFIG); + // Prepend the prefix if (*data->prefix) { // Compose file path r = pakfire_path_join(buffer, data->prefix, path); if (r) { ERROR(pakfire, "Could not compose file path: %m\n"); - return r; + goto ERROR; } // Set file path @@ -719,7 +723,7 @@ static int __pakfire_extract(struct pakfire* pakfire, struct archive* a, r = pakfire_path_join(buffer, data->prefix, link); if (r) { ERROR(pakfire, "Could not compose hardlink path: %m\n"); - return r; + goto ERROR; } // Set hardlink path @@ -727,6 +731,25 @@ static int __pakfire_extract(struct pakfire* pakfire, struct archive* a, } } + if (configfile) { + // Fetch path again since we changed it + path = archive_entry_pathname(entry); + + if (pakfire_path_exists(path)) { + DEBUG(pakfire, "The configuration file %s exists\n", + pakfire_file_get_path(file)); + + r = pakfire_string_format(buffer, "%s.paknew", path); + if (r) { + ERROR(pakfire, "Could not compose path for configuration file: %m\n"); + goto ERROR; + } + + // Set the path again + archive_entry_set_pathname(entry, buffer); + } + } + // Create file & extract payload if (data->writer) { // Fetch path again since we changed it -- 2.47.3