[gnome-autoar/wip/oholy/drop-recursive-delete] extractor: Drop recursive delete on failure to prevent data loss




commit 9d58a9dcde3c4a74107674b847189d41bbe22b6c
Author: Ondrej Holy <oholy redhat com>
Date:   Mon Feb 22 12:54:00 2021 +0100

    extractor: Drop recursive delete on failure to prevent data loss
    
    Recursive delete has been added by commit 58ac8fc5 to remove already created
    directories when extraction fails because of an invalid password. In fact,
    it deletes the whole `destination_dir` also in case of other failures, which
    is maybe not the best approach, but ok. However, a problem is that
    gnome-autoar allows extraction in non-empty destination, so this might remove
    also files which were not initially created by gnome-autoar. Fortunately,
    nautilus and gnome-shell currently always extracts in an extra directory. But
    what is worse is the fact, that if the files in the archive have a common
    prefix, then the `destination_dir` is actually a parent of that extra directory
    in the case of nautilus and gnome-shell (but API allows to set completely
    unrelated path)! So this can easily cause huge data loss! It would probably be
    better to create parent directories only when `archive_read_data_block`
    succeeds instead of deleting them later. Alternatively, gnome-autoar could
    track which files were written and deletes just those on that list. But for now,
    let's just remove the code for recursive delete and do not care about leftover
    files...

 gnome-autoar/autoar-extractor.c | 52 -----------------------------------------
 1 file changed, 52 deletions(-)
---
diff --git a/gnome-autoar/autoar-extractor.c b/gnome-autoar/autoar-extractor.c
index 37e57ed..8f31e20 100644
--- a/gnome-autoar/autoar-extractor.c
+++ b/gnome-autoar/autoar-extractor.c
@@ -992,57 +992,6 @@ autoar_extractor_check_file_conflict (GFile  *file,
   return conflict;
 }
 
-static gboolean
-autoar_extractor_delete_file_recursively (AutoarExtractor *self,
-                                          GFile *file)
-{
-  gboolean success;
-  g_autoptr (GError) error = NULL;
-
-  do {
-    g_autoptr (GFileEnumerator) enumerator = NULL;
-
-    success = g_file_delete (file, self->cancellable, &error);
-    if (success || !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_EMPTY)) {
-      break;
-    }
-
-    g_clear_error (&error);
-    enumerator = g_file_enumerate_children (file,
-                                            G_FILE_ATTRIBUTE_STANDARD_NAME,
-                                            G_FILE_QUERY_INFO_NONE,
-                                            self->cancellable, &error);
-    if (enumerator) {
-      GFileInfo *info;
-
-      success = TRUE;
-
-      info = g_file_enumerator_next_file (enumerator,
-                                          self->cancellable,
-                                          &error);
-      while (info != NULL) {
-        g_autoptr (GFile) child = NULL;
-
-        child = g_file_enumerator_get_child (enumerator, info);
-
-        success = success && autoar_extractor_delete_file_recursively (self, child);
-        g_object_unref (info);
-
-        info = g_file_enumerator_next_file (enumerator,
-                                            self->cancellable,
-                                            &error);
-      }
-    }
-
-    if (error != NULL) {
-      success = FALSE;
-    }
-
-  } while (success);
-
-  return success;
-}
-
 static void
 autoar_extractor_do_write_entry (AutoarExtractor      *self,
                                  struct archive       *a,
@@ -1242,7 +1191,6 @@ autoar_extractor_do_write_entry (AutoarExtractor      *self,
             }
 
             if (r == ARCHIVE_FAILED) {
-              autoar_extractor_delete_file_recursively (self, self->destination_dir);
               if (self->error == NULL) {
                 self->error = g_error_new (AUTOAR_EXTRACTOR_ERROR,
                                            INCORRECT_PASSPHRASE_ERRNO,


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