[Pkg-privacy-commits] [nautilus-wipe] 57/224: Use paths instead of NFIs for operations

Ulrike Uhlig u-guest at moszumanska.debian.org
Thu Jul 7 19:45:34 UTC 2016


This is an automated email from the git hooks/post-receive script.

u-guest pushed a commit to branch master
in repository nautilus-wipe.

commit 4878d22528bb4c4666d68c600f697e37cef2ed83
Author: Colomban Wendling <ban at herbesfolles.org>
Date:   Fri Feb 26 00:41:06 2010 +0100

    Use paths instead of NFIs for operations
    
    Switch from NautilusFileInfos to paths in operations.
    We never used the NautilusFileInfo to anything else that getting the
    local path, duplicating code between operations. By a matter of facts,
    it is no longer each operation that have to deal with non-local paths,
    allowing a more generic handling of this.
---
 nautilus-srm/delete-operation.c  |  31 ++---------
 nautilus-srm/fill-operation.c    |  62 +++++++--------------
 nautilus-srm/nautilus-srm.c      | 116 ++++++++++++++++++++++++++++++++-------
 nautilus-srm/operation-manager.c |   2 +-
 nautilus-srm/operation-manager.h |   2 +-
 5 files changed, 125 insertions(+), 88 deletions(-)

diff --git a/nautilus-srm/delete-operation.c b/nautilus-srm/delete-operation.c
index f29159d..d4bf3c0 100644
--- a/nautilus-srm/delete-operation.c
+++ b/nautilus-srm/delete-operation.c
@@ -29,14 +29,11 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 #include <gsecuredelete/gsecuredelete.h>
-#include <libnautilus-extension/nautilus-file-info.h>
-
-#include "compat.h" /* for nautilus_file_info_get_location() */
 
 
 /*
  * nsrm_delete_operation:
- * @files: A list of #NautilusFileInfo to delete.
+ * @files: A list of paths to delete.
  * @fast: The Gsd.SecureDeleteOperation:fast setting
  * @mode: The Gsd.SecureDeleteOperation:mode setting
  * @zeroise: The Gsd.ZeroableOperation:zeroise setting
@@ -67,32 +64,16 @@ nautilus_srm_delete_operation (GList                       *files,
   guint               n_files = 0;
   
   operation = gsd_delete_operation_new ();
-  for (; success && files; files = g_list_next (files)) {
-    GFile *file = nautilus_file_info_get_location (files->data);
-    gchar *path;
-    
-    path = g_file_get_path (file);
-    if (! path) {
-      gchar *uri = g_file_get_uri (file);
-      
-      success = FALSE;
-      /* FIXME: use correct error quark and code */
-      g_set_error (error, 0, 0, "Unsupported location: %s", uri);
-      g_free (uri);
-    } else {
-      gsd_delete_operation_add_path (operation, path);
-    }
-    g_free (path);
-    g_object_unref (file);
+  for (; files; files = g_list_next (files)) {
+    gsd_delete_operation_add_path (operation, files->data);
     n_files ++;
   }
-  if (success && n_files < 1) {
+  if (n_files < 1) {
     /* FIXME: use correct error quark and code */
     g_set_error (error, 0, 0, "Nothing to do!");
     success = FALSE;
-  }
-  /* if file addition succeeded, try to launch operation */
-  if (success) {
+  } else {
+    /* if file addition succeeded, try to launch operation */
     gsd_secure_delete_operation_set_fast (GSD_SECURE_DELETE_OPERATION (operation), fast);
     gsd_secure_delete_operation_set_mode (GSD_SECURE_DELETE_OPERATION (operation), mode);
     gsd_zeroable_operation_set_zeroise (GSD_ZEROABLE_OPERATION (operation), zeroise);
diff --git a/nautilus-srm/fill-operation.c b/nautilus-srm/fill-operation.c
index 8268c2b..4af87fc 100644
--- a/nautilus-srm/fill-operation.c
+++ b/nautilus-srm/fill-operation.c
@@ -32,9 +32,6 @@
 # include <gio/gunixmounts.h>
 #endif
 #include <gsecuredelete/gsecuredelete.h>
-#include <libnautilus-extension/nautilus-file-info.h>
-
-#include "compat.h" /* for nautilus_file_info_get_location() */
 
 
 #if HAVE_GIO_UNIX
@@ -84,14 +81,16 @@ find_mountpoint_unix (const gchar *path)
 #endif
 
 static gchar *
-find_mountpoint (GFile   *file,
-                 GError **error)
+find_mountpoint (const gchar *path,
+                 GError     **error)
 {
   gchar  *mountpoint_path = NULL;
+  GFile  *file;
   GMount *mount;
   GError *err = NULL;
   
   /* Try with GIO first */
+  file = g_file_new_for_path (path);
   mount = g_file_find_enclosing_mount (file, NULL, &err);
   if (mount) {
     GFile *mountpoint_file;
@@ -107,24 +106,15 @@ find_mountpoint (GFile   *file,
     g_object_unref (mountpoint_file);
     g_object_unref (mount);
   }
+  g_object_unref (file);
   #if HAVE_GIO_UNIX
   /* fallback to find_unix_mount() */
   if (! mountpoint_path) {
-    gchar *path = g_file_get_path (file);
-    
     g_clear_error (&err);
-    if (path) {
-      mountpoint_path = find_mountpoint_unix (path);
-      if (! mountpoint_path) {
-        g_set_error (&err, 0, 0, "No mount point found for path \"%s\"", path);
-      }
-    } else {
-      gchar *uri = g_file_get_uri (file);
-      
-      g_set_error (&err, 0, 0, "File \"%s\" is not local", uri);
-      g_free (uri);
+    mountpoint_path = find_mountpoint_unix (path);
+    if (! mountpoint_path) {
+      g_set_error (&err, 0, 0, "No mount point found for path \"%s\"", path);
     }
-    g_free (path);
   }
   #endif
   if (! mountpoint_path) {
@@ -275,7 +265,7 @@ nautilus_srm_fill_finished_handler (GsdFillOperation         *operation,
 
 /*
  * filter_dir_list:
- * @directories: a list of #NautilusFileInfo
+ * @directories: a list of paths
  * 
  * Filter the input file list so that there remains only one path for
  * each filesystem.
@@ -297,10 +287,10 @@ filter_dir_list (GList   *directories,
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
   
   for (; ! err && directories; directories = g_list_next (directories)) {
-    GFile *file = nautilus_file_info_get_location (directories->data);
-    gchar *mountpoint;
+    const gchar  *file_path = directories->data;
+    gchar        *mountpoint;
     
-    mountpoint = find_mountpoint (file, &err);
+    mountpoint = find_mountpoint (file_path, &err);
     if (G_LIKELY (mountpoint)) {
       if (g_hash_table_lookup (mountpoints, mountpoint)) {
         /* the mountpoint is already added, skip it */
@@ -309,29 +299,17 @@ filter_dir_list (GList   *directories,
         gchar *path;
         
         g_hash_table_insert (mountpoints, mountpoint, (gpointer)TRUE);
-        path = g_file_get_path (file);
-        if (! path) {
-          /* FIXME: fix error domain & code */
-          gchar *uri = g_file_get_uri (file);
-          
-          g_set_error (&err, 0, 0, "Cannot find local path for URI \"%s\"", uri);
-          g_free (uri);
+        /* if it is not a directory, gets its container directory.
+         * no harm since files cannot be mountpoint themselves, then it gets
+         * at most the mountpoint itself */
+        if (! g_file_test (file_path, G_FILE_TEST_IS_DIR)) {
+          path = g_path_get_dirname (file_path);
         } else {
-          /* if it is not a directory, gets its container directory.
-           * no harm since files cannot be mountpoint themselves, then it gets
-           * at most the mountpoint itself */
-          if (! g_file_test (path, G_FILE_TEST_IS_DIR)) {
-            gchar *tmp;
-            
-            tmp = g_path_get_dirname (path);
-            g_free (path);
-            path = tmp;
-          }
-          dirs = g_list_append (dirs, path);
+          path = g_strdup (file_path);
         }
+        dirs = g_list_append (dirs, path);
       }
     }
-    g_object_unref (file);
   }
   g_hash_table_destroy (mountpoints);
   if (err) {
@@ -350,7 +328,7 @@ filter_dir_list (GList   *directories,
 
 /*
  * nautilus_srm_fill_operation:
- * @directories: A list of #NautilusFileInfo to work on
+ * @directories: A list of paths to work on
  * @fast: The Gsd.SecureDeleteOperation:fast setting
  * @mode: The Gsd.SecureDeleteOperation:mode setting
  * @zeroise: The Gsd.ZeroableOperation:zeroise setting
diff --git a/nautilus-srm/nautilus-srm.c b/nautilus-srm/nautilus-srm.c
index 06fc315..4bd92bf 100644
--- a/nautilus-srm/nautilus-srm.c
+++ b/nautilus-srm/nautilus-srm.c
@@ -34,6 +34,7 @@
 #include "operation-manager.h"
 #include "delete-operation.h"
 #include "fill-operation.h"
+#include "compat.h"
 
 
 static GType provider_types[1];
@@ -175,6 +176,77 @@ static void       run_delete_operation  (GtkWindow *parent,
                                          GList     *files);
 
 
+/* gets the path of a #NautilusFileInfo. */
+static gchar *
+nautilus_srm_nfi_get_path (NautilusFileInfo *nfi)
+{
+  GFile *file;
+  gchar *path;
+  
+  file = nautilus_file_info_get_location (nfi);
+  path = g_file_get_path (file);
+  
+  return path;
+}
+
+/* frees a list of paths */
+static void
+nautilus_srm_path_list_free (GList *paths)
+{
+  while (paths) {
+    GList *tmp = paths;
+    
+    paths = g_list_next (paths);
+    g_free (tmp->data);
+    g_list_free_1 (tmp);
+  }
+}
+
+/* copies a list of paths
+ * free the returned list with nautilus_srm_path_list_free() */
+static GList *
+nautilus_srm_path_list_copy (GList *src)
+{
+  GList *paths = NULL;
+  
+  while (src) {
+    paths = g_list_append (paths, g_strdup (src->data));
+    src = g_list_next (src);
+  }
+  
+  return paths;
+}
+
+/* converts a list of #NautilusFileInfo to a list of paths.
+ * free the returned list with nautilus_srm_path_list_free()
+ * 
+ * Returns: The list of paths on success, or %NULL on failure. This function
+ *          will always fail on non-local-mounted (then without paths) files */
+static GList *
+nautilus_srm_nfi_list_to_path_list (GList *nfis)
+{
+  gboolean  success = TRUE;
+  GList    *paths   = NULL;
+  
+  while (nfis && success) {
+    gchar *path;
+    
+    path = nautilus_srm_nfi_get_path (nfis->data);
+    if (path) {
+      paths = g_list_append (paths, path);
+    } else {
+      success = FALSE;
+    }
+    nfis = g_list_next (nfis);
+  }
+  if (! success) {
+    nautilus_srm_path_list_free (paths);
+    paths = NULL;
+  }
+  
+  return paths;
+}
+
 
 /* Data needed to be able to start an operation.
  * We don't use private filed of the extension's object because there is only
@@ -186,14 +258,14 @@ struct ItemData
                        * Note: don't ref or unref it, it seems to break
                        * something in Nautilus (like the object being alive but
                        * the widget destroyed... strange) */
-  GList     *files;   /* list of selected NautilusFileInfos */
+  GList     *paths;   /* list of selected paths */
 };
 
 /* Frees an #ItemData */
 static void
 item_data_free (struct ItemData *idata)
 {
-  nautilus_file_info_list_free (idata->files);
+  nautilus_srm_path_list_free (idata->paths);
   g_slice_free1 (sizeof *idata, idata);
 }
 
@@ -204,7 +276,7 @@ item_data_free (struct ItemData *idata)
 static void
 add_item_data (NautilusMenuItem *item,
                GtkWidget        *window,
-               GList            *files)
+               GList            *paths)
 {
   struct ItemData *idata;
   
@@ -213,7 +285,7 @@ add_item_data (NautilusMenuItem *item,
    * GtkWindow. This would not be a problem since at this time the user will
    * not (even be able to) activate our button. */
   idata->window = GTK_IS_WINDOW (window) ? GTK_WINDOW (window) : NULL;
-  idata->files = nautilus_file_info_list_copy (files);
+  idata->paths = nautilus_srm_path_list_copy (paths);
   g_object_set_data_full (G_OBJECT (item), "NautilusSrm::item-data",
                           idata, (GDestroyNotify)item_data_free);
 }
@@ -235,14 +307,14 @@ menu_item_delete_activate_handler (NautilusMenuItem     *item,
 {
   struct ItemData *idata = get_item_data (item);
   
-  run_delete_operation (idata->window, idata->files);
+  run_delete_operation (idata->window, idata->paths);
 }
 
 static NautilusMenuItem *
 nautilus_srm_menu_item_srm (NautilusMenuProvider *provider,
                             const gchar          *item_name,
                             GtkWidget            *window,
-                            GList                *files)
+                            GList                *paths)
 {
   NautilusMenuItem *item;
   
@@ -250,9 +322,9 @@ nautilus_srm_menu_item_srm (NautilusMenuProvider *provider,
                                  _("Delete and overwrite content"),
                                  g_dngettext (NULL, "Delete the selected file and overwrite its data",
                                                     "Delete the selected files and overwrite their data",
-                                                    g_list_length (files)),
+                                                    g_list_length (paths)),
                                  GTK_STOCK_DELETE);
-  add_item_data (item, window, files);
+  add_item_data (item, window, paths);
   g_signal_connect (item, "activate",
                     G_CALLBACK (menu_item_delete_activate_handler), provider);
   
@@ -266,7 +338,7 @@ menu_item_fill_activate_handler (NautilusMenuItem     *item,
 {
   struct ItemData *idata = get_item_data (item);
   
-  run_fill_operation (idata->window, idata->files);
+  run_fill_operation (idata->window, idata->paths);
 }
 
 static NautilusMenuItem *
@@ -297,15 +369,18 @@ nautilus_srm_get_file_items (NautilusMenuProvider *provider,
                              GList                *files)
 {
   GList *items = NULL;
+  GList *paths;
   
-  if (files) {
+  paths = nautilus_srm_nfi_list_to_path_list (files);
+  if (paths) {
     items = g_list_append (items, nautilus_srm_menu_item_srm (provider,
                                                               "nautilus-srm::files-items::srm",
-                                                              window, files));
+                                                              window, paths));
     items = g_list_append (items, nautilus_srm_menu_item_sfill (provider,
                                                                 "nautilus-srm::files-items::sfill",
-                                                                window, files));
+                                                                window, paths));
   }
+  nautilus_srm_path_list_free (paths);
   
   return items;
 }
@@ -317,12 +392,15 @@ nautilus_srm_get_background_items (NautilusMenuProvider *provider,
                                    NautilusFileInfo     *current_folder)
 {
   GList *items = NULL;
-  GList *files = g_list_append (NULL, current_folder);
+  GList *paths = NULL;
   
-  items = g_list_append (items, nautilus_srm_menu_item_sfill (provider,
-                                                              "nautilus-srm::background-items::sfill",
-                                                              window, files));
-  g_list_free (files);
+  paths = g_list_append (paths, nautilus_srm_nfi_get_path (current_folder));
+  if (paths && paths->data) {
+    items = g_list_append (items, nautilus_srm_menu_item_sfill (provider,
+                                                                "nautilus-srm::background-items::sfill",
+                                                                window, paths));
+  }
+  nautilus_srm_path_list_free (paths);
   
   return items;
 }
@@ -345,7 +423,7 @@ run_delete_operation (GtkWindow *parent,
   } else if (n_items > 0) {
     gchar *name;
     
-    name = nautilus_file_info_get_name (files->data);
+    name = g_filename_display_basename (files->data);
     confirm_primary_text = g_strdup_printf (_("Are you sure you want to delete and wipe "
                                               "\"%s\"?"),
                                             name);
@@ -387,7 +465,7 @@ run_fill_operation (GtkWindow *parent,
   } else if (n_items > 0) {
     gchar *name;
     
-    name = nautilus_file_info_get_name (files->data);
+    name = g_filename_display_basename (files->data);
     confirm_primary_text = g_strdup_printf (_("Are you sure you want to wipe the free space "
                                               "on the device of \"%s\"?"),
                                             name);
diff --git a/nautilus-srm/operation-manager.c b/nautilus-srm/operation-manager.c
index 0b159eb..81561e3 100644
--- a/nautilus-srm/operation-manager.c
+++ b/nautilus-srm/operation-manager.c
@@ -374,7 +374,7 @@ progress_dialog_response_handler (GtkDialog *dialog,
 /* 
  * nautilus_srm_operation_manager_run:
  * @parent: Parent window for dialogs
- * @files: List of #NautilusFileInfo to pass to @operation_launcher_func
+ * @files: List of paths to pass to @operation_launcher_func
  * @confirm_primary_text: Primary text for the confirmation dialog
  * @confirm_secondary_text: Secondary text for the confirmation dialog
  * @confirm_button_text: Text for the confirm button of the confirmation dialog.
diff --git a/nautilus-srm/operation-manager.h b/nautilus-srm/operation-manager.h
index 0838107..8bd8878 100644
--- a/nautilus-srm/operation-manager.h
+++ b/nautilus-srm/operation-manager.h
@@ -32,7 +32,7 @@ G_BEGIN_DECLS
 
 /**
  * NautilusSrmOperationFunc:
- * @files: Files to work on
+ * @files: Paths to work on
  * @fast: The Gsd.SecureDeleteOperation:fast setting
  * @mode: The Gsd.SecureDeleteOperation:mode setting
  * @zeroise: The Gsd.ZeroableOperation:zeroise setting

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/nautilus-wipe.git



More information about the Pkg-privacy-commits mailing list