[gnome-autoar/wip/oholy/various-fixes: 12/17] extractor: Explicitely delete files that should be overwritten




commit df307afcc7260163498949c9a7be25a9e7ddf619
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Feb 24 16:31:53 2021 +0100

    extractor: Explicitely delete files that should be overwritten
    
    Currently, `g_file_replace` is used to write files. However, it uses
    `G_FILE_CREATE_NONE` which keeps old permissions. It should rather use
    `G_FILE_CREATE_REPLACE_DESTINATION` instead to not keep any old permissions
    as it is among others used by File Roller. However, there is bug in
    `G_FILE_CREATE_REPLACE_DESTINATION` implementaion, see GNOME/glib#2325.
    Let's explicitely delete that file and use `g_file_create` instead.
    This will also fix problems when overwriting file by directory and
    ensures that hardlinks will be replaced and not just modified.

 gnome-autoar/autoar-extractor.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/gnome-autoar/autoar-extractor.c b/gnome-autoar/autoar-extractor.c
index a897ae9..97775f7 100644
--- a/gnome-autoar/autoar-extractor.c
+++ b/gnome-autoar/autoar-extractor.c
@@ -1203,12 +1203,10 @@ autoar_extractor_do_write_entry (AutoarExtractor      *self,
 
         g_debug ("autoar_extractor_do_write_entry: case REG");
 
-        ostream = (GOutputStream*)g_file_replace (dest,
-                                                  NULL,
-                                                  FALSE,
-                                                  G_FILE_CREATE_NONE,
-                                                  self->cancellable,
-                                                  &(self->error));
+        ostream = (GOutputStream*)g_file_create (dest,
+                                                 G_FILE_CREATE_NONE,
+                                                 self->cancellable,
+                                                 &(self->error));
         if (self->error != NULL) {
           g_object_unref (info);
           return;
@@ -2015,6 +2013,14 @@ autoar_extractor_step_extract (AutoarExtractor *self) {
 
       switch (action) {
         case AUTOAR_CONFLICT_OVERWRITE:
+          /* It is expected that this will fail for non-empty directories to
+           * prevent data loss.
+           */
+          g_file_delete (extracted_filename, self->cancellable, &self->error);
+          if (self->error != NULL) {
+            archive_read_free (a);
+            return;
+          }
           break;
         case AUTOAR_CONFLICT_CHANGE_DESTINATION:
           g_assert_nonnull (new_extracted_filename);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]