[gnome-autoar/wip/oholy/various-fixes: 13/17] extractor: Detect conflict also for directories




commit 67f073d851426b4cd93abbcf6621f217a8093901
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Feb 25 14:10:26 2021 +0100

    extractor: Detect conflict also for directories
    
    Current logic doesn't detect conflics when extracting directory. This
    is ok, but only for the case when the conflic is caused by directory.
    Otherwise, the conflic should be detected and AutoarExtractor should
    try to delete the file before creating new directory.

 gnome-autoar/autoar-extractor.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)
---
diff --git a/gnome-autoar/autoar-extractor.c b/gnome-autoar/autoar-extractor.c
index 97775f7..46e304e 100644
--- a/gnome-autoar/autoar-extractor.c
+++ b/gnome-autoar/autoar-extractor.c
@@ -964,7 +964,6 @@ autoar_extractor_check_file_conflict (GFile  *file,
                                       mode_t  extracted_filetype)
 {
   GFileType file_type;
-  gboolean conflict = FALSE;
 
   file_type = g_file_query_file_type (file,
                                       G_FILE_QUERY_INFO_NONE,
@@ -974,26 +973,13 @@ autoar_extractor_check_file_conflict (GFile  *file,
     return FALSE;
   }
 
-  switch (extracted_filetype) {
-    case AE_IFDIR:
-      break;
-    case AE_IFREG:
-    case AE_IFLNK:
-#if defined HAVE_MKFIFO || defined HAVE_MKNOD
-    case AE_IFIFO:
-#endif
-#ifdef HAVE_MKNOD
-    case AE_IFSOCK:
-    case AE_IFBLK:
-    case AE_IFCHR:
-#endif
-      conflict = TRUE;
-      break;
-    default:
-      break;
+  /* It is not problem if the directory already exists */
+  if (file_type == G_FILE_TYPE_DIRECTORY &&
+      extracted_filetype == AE_IFDIR) {
+    return FALSE;
   }
 
-  return conflict;
+  return TRUE;
 }
 
 static gboolean
@@ -2023,6 +2009,9 @@ autoar_extractor_step_extract (AutoarExtractor *self) {
           }
           break;
         case AUTOAR_CONFLICT_CHANGE_DESTINATION:
+          /* FIXME: If the destination is changed for directory, it should be
+           * changed also for its children...
+           */
           g_assert_nonnull (new_extracted_filename);
           g_clear_object (&extracted_filename);
           extracted_filename = new_extracted_filename;


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