]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
compress: Do not overwrite configuration on extraction
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 15 Mar 2023 18:40:49 +0000 (18:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 15 Mar 2023 18:40:49 +0000 (18:40 +0000)
This is somewhat experimental and I would need to think a little bit
more about this.

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

index 8a5d793ba1ec1a56707a9e38279f668990633f96..88dbdab2dd6bb4d259c00658f3f24b9dde657efb 100644 (file)
@@ -32,6 +32,7 @@
 #include <pakfire/filelist.h>
 #include <pakfire/logging.h>
 #include <pakfire/progressbar.h>
+#include <pakfire/string.h>
 #include <pakfire/util.h>
 
 // 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