[gnome-autoar/wip/razvan/extract-refactor2: 5/8] AutoarExtract: remove pattern checking



commit ee652b3308f04279a6969669794aca7940462f4f
Author: Razvan Chitu <razvan ch95 gmail com>
Date:   Wed Aug 3 17:33:02 2016 +0300

    AutoarExtract: remove pattern checking
    
    Filtering extracted files by pathname should not be the responsibility of the
    AutoarExtract instances.

 gnome-autoar/autoar-extract.c |  102 +++--------------------------------------
 1 files changed, 7 insertions(+), 95 deletions(-)
---
diff --git a/gnome-autoar/autoar-extract.c b/gnome-autoar/autoar-extract.c
index ab3cf31..a276fb8 100644
--- a/gnome-autoar/autoar-extract.c
+++ b/gnome-autoar/autoar-extract.c
@@ -77,10 +77,6 @@
  * new output destination to be used instead of the one provided by
  * #AutoarExtract. This is convenient for solving name conflicts and
  * implementing specific logic based on the contents of the archive.
-
- * #AutoarExtract can also ignore specific file name pattern when extrating,
- * or delete the source archive after extracting, depending on the settings
- * provided by the #AutoarPref object.
  *
  * When #AutoarExtract stops all work, it will emit one of the three signals:
  * #AutoarExtract::cancelled, #AutoarExtract::error, and
@@ -150,8 +146,6 @@ struct _AutoarExtractPrivate
 
   GHashTable *userhash;
   GHashTable *grouphash;
-  GHashTable *bad_filename;
-  GPtrArray  *pattern_compiled;
   GArray     *extracted_dir_list;
   GFile      *destination_dir;
 
@@ -559,16 +553,6 @@ autoar_extract_dispose (GObject *object)
     priv->grouphash = NULL;
   }
 
-  if (priv->bad_filename != NULL) {
-    g_hash_table_unref (priv->bad_filename);
-    priv->bad_filename = NULL;
-  }
-
-  if (priv->pattern_compiled != NULL) {
-    g_ptr_array_unref (priv->pattern_compiled);
-    priv->pattern_compiled = NULL;
-  }
-
   if (priv->extracted_dir_list != NULL) {
     g_array_unref (priv->extracted_dir_list);
     priv->extracted_dir_list = NULL;
@@ -794,13 +778,6 @@ libarchive_create_read_object (gboolean use_raw_format,
 }
 
 static void
-g_pattern_spec_free_safe (void *pattern_compiled)
-{
-  if (pattern_compiled != NULL)
-    g_pattern_spec_free (pattern_compiled);
-}
-
-static void
 g_file_and_info_free (void *g_file_and_info)
 {
   GFileAndInfo *fi = g_file_and_info;
@@ -983,42 +960,6 @@ autoar_extract_do_sanitize_pathname (AutoarExtract *arextract,
 }
 
 static gboolean
-autoar_extract_do_pattern_check (const char *path,
-                                 GPtrArray *pattern)
-{
-  char **path_components;
-  GArray *path_components_len;
-
-  int i, j, len;
-
-  path_components = g_strsplit (path, "/", G_MAXINT);
-  path_components_len = g_array_new (FALSE, FALSE, sizeof(size_t));
-  for (i = 0; path_components[i] != NULL; i++) {
-    len = strlen (path_components[i]);
-    g_array_append_val (path_components_len, len);
-  }
-
-  for (i = 0; g_ptr_array_index (pattern, i) != NULL; i++) {
-    for (j = 0; path_components[j] != NULL; j++) {
-      if (g_pattern_match (g_ptr_array_index (pattern, i),
-                           g_array_index (path_components_len, size_t, j),
-                           path_components[j],
-                           NULL)) {
-        g_debug ("autoar_extract_do_pattern_check: ### %s", path_components[j]);
-        g_strfreev (path_components);
-        g_array_unref (path_components_len);
-        return FALSE;
-      }
-    }
-  }
-
-  g_strfreev (path_components);
-  g_array_unref (path_components_len);
-
-  return TRUE;
-}
-
-static gboolean
 autoar_extract_check_file_conflict (GFile *file,
                                     mode_t extracted_filetype)
 {
@@ -1657,8 +1598,6 @@ autoar_extract_init (AutoarExtract *arextract)
 
   priv->userhash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
   priv->grouphash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-  priv->bad_filename = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-  priv->pattern_compiled = g_ptr_array_new_with_free_func (g_pattern_spec_free_safe);
   priv->extracted_dir_list = g_array_new (FALSE, FALSE, sizeof (GFileAndInfo));
   g_array_set_clear_func (priv->extracted_dir_list, g_file_and_info_free);
   priv->destination_dir = NULL;
@@ -1857,26 +1796,9 @@ autoar_extract_new_memory_file (const void *buffer,
 }
 
 static void
-autoar_extract_step_initialize_pattern (AutoarExtract *arextract) {
-  /* Step 0: Compile the file name pattern. */
-
-  AutoarExtractPrivate *priv = arextract->priv;
-  const char **pattern = autoar_pref_get_pattern_to_ignore (priv->arpref);
-  int i;
-
-  g_debug ("autoar_extract_step_initialize_pattern: called");
-
-  if (pattern != NULL) {
-    for (i = 0; pattern[i] != NULL; i++)
-      g_ptr_array_add (priv->pattern_compiled, g_pattern_spec_new (pattern[i]));
-  }
-  g_ptr_array_add (priv->pattern_compiled, NULL);
-}
-
-static void
 autoar_extract_step_scan_toplevel (AutoarExtract *arextract)
 {
-  /* Step 1: Scan all file names in the archive
+  /* Step 0: Scan all file names in the archive
    * We have to check whether the archive contains a top-level directory
    * before performing the extraction. We emit the "scanned" signal when
    * the checking is completed. */
@@ -1925,13 +1847,6 @@ autoar_extract_step_scan_toplevel (AutoarExtract *arextract)
     priv->files_list = g_list_prepend (priv->files_list,
                                        g_file_get_child (priv->output_file, pathname));
 
-    if (!priv->use_raw_format && !autoar_extract_do_pattern_check (pathname, priv->pattern_compiled)) {
-      g_hash_table_insert (priv->bad_filename, g_strdup (pathname), GUINT_TO_POINTER (TRUE));
-      continue;
-    }
-
-    g_debug ("autoar_extract_step_scan_toplevel: %d: pattern check passed", priv->files);
-
     priv->files++;
     priv->size += archive_entry_size (entry);
     archive_read_data_skip (a);
@@ -1980,7 +1895,7 @@ autoar_extract_step_scan_toplevel (AutoarExtract *arextract)
 static void
 autoar_extract_step_set_dest (AutoarExtract *arextract)
 {
-  /* Step 2: Set destination based on client preferences or archive contents */
+  /* Step 1: Set destination based on client preferences or archive contents */
 
   AutoarExtractPrivate *priv;
 
@@ -2022,7 +1937,7 @@ autoar_extract_step_set_dest (AutoarExtract *arextract)
 static void
 autoar_extract_step_decide_dest (AutoarExtract *arextract)
 {
-  /* Step 3: Confirm destination */
+  /* Step 2: Confirm destination */
 
   AutoarExtractPrivate *priv;
   GList *files = NULL;
@@ -2098,7 +2013,7 @@ autoar_extract_step_decide_dest (AutoarExtract *arextract)
 
 static void
 autoar_extract_step_extract (AutoarExtract *arextract) {
-  /* Step 4: Extract files
+  /* Step 3: Extract files
    * We have to re-open the archive to extract files */
 
   struct archive *a;
@@ -2133,8 +2048,6 @@ autoar_extract_step_extract (AutoarExtract *arextract) {
 
     pathname = archive_entry_pathname (entry);
     hardlink = archive_entry_hardlink (entry);
-    if (GPOINTER_TO_UINT (g_hash_table_lookup (priv->bad_filename, pathname)))
-      continue;
 
     extracted_filename =
       autoar_extract_do_sanitize_pathname (arextract, pathname);
@@ -2200,7 +2113,7 @@ autoar_extract_step_extract (AutoarExtract *arextract) {
 
 static void
 autoar_extract_step_apply_dir_fileinfo (AutoarExtract *arextract) {
-  /* Step 5: Re-apply file info to all directories
+  /* Step 4: Re-apply file info to all directories
    * It is required because modification times may be updated during the
    * writing of files in the directory. */
 
@@ -2225,7 +2138,7 @@ autoar_extract_step_apply_dir_fileinfo (AutoarExtract *arextract) {
 
 static void
 autoar_extract_step_cleanup (AutoarExtract *arextract) {
-  /* Step 6: Force progress to be 100% and remove the source archive file
+  /* Step 5: Force progress to be 100% and remove the source archive file
    * If the extraction is completed successfully, remove the source file.
    * Errors are not fatal because we have completed our work. */
 
@@ -2251,7 +2164,7 @@ autoar_extract_run (AutoarExtract *arextract)
 {
   /* Numbers of steps.
    * The array size must be modified if more steps are added. */
-  void (*steps[8])(AutoarExtract*);
+  void (*steps[7])(AutoarExtract*);
 
   AutoarExtractPrivate *priv;
   int i;
@@ -2269,7 +2182,6 @@ autoar_extract_run (AutoarExtract *arextract)
   }
 
   i = 0;
-  steps[i++] = autoar_extract_step_initialize_pattern;
   steps[i++] = autoar_extract_step_scan_toplevel;
   steps[i++] = autoar_extract_step_set_dest;
   steps[i++] = autoar_extract_step_decide_dest;


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