[Pkg-privacy-commits] [nautilus-wipe] 64/224: Filter input of fill_operation outside of the operation launcher
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 bc86de6b9f618e3cecbb4e85e031c8caef4a4dc6
Author: Colomban Wendling <ban at herbesfolles.org>
Date: Fri Mar 12 23:59:52 2010 +0100
Filter input of fill_operation outside of the operation launcher
This allows:
* Not to show the menu item if we have nothing valuable to work on;
* To know the mountpoint list as well as the path list wen asking
the user for approval.
---
nautilus-srm/fill-operation.c | 75 ++++++++++++++++++---------------
nautilus-srm/fill-operation.h | 4 ++
nautilus-srm/nautilus-srm.c | 96 ++++++++++++++++++++++++++++---------------
nautilus-srm/nautilus-srm.h | 8 +++-
4 files changed, 115 insertions(+), 68 deletions(-)
diff --git a/nautilus-srm/fill-operation.c b/nautilus-srm/fill-operation.c
index 4af87fc..da6be1e 100644
--- a/nautilus-srm/fill-operation.c
+++ b/nautilus-srm/fill-operation.c
@@ -32,6 +32,7 @@
# include <gio/gunixmounts.h>
#endif
#include <gsecuredelete/gsecuredelete.h>
+#include "nautilus-srm.h"
#if HAVE_GIO_UNIX
@@ -264,41 +265,48 @@ nautilus_srm_fill_finished_handler (GsdFillOperation *operation,
}
/*
- * filter_dir_list:
- * @directories: a list of paths
+ * nautilus_srm_fill_operation_filter_files:
+ * @paths: A list of paths to filter
+ * @work_paths_: return location for filtered paths
+ * @work_mounts_: return location for filtered paths' mounts
+ * @error: return location for errors, or %NULL to ignore them
*
- * Filter the input file list so that there remains only one path for
- * each filesystem.
+ * Ties to get usable paths (local directories) and keep only one per
+ * mountpoint.
*
- * Returns: A #GList of file pathes to actually work on. Free each element with
- * g_free() before freeing the list.
+ * The returned lists (@work_paths_ and @work_mounts_) have the same length, and
+ * an index in a list correspond to the same in the other:
+ * g_list_index(work_paths_, 0) is the path of g_list_index(work_mounts_, 0).
+ * Free returned lists with nautilus_srm_path_list_free().
+ *
+ * Returns: %TRUE on success, %FALSE otherwise.
*/
-static GList *
-filter_dir_list (GList *directories,
- GError **error)
+gboolean
+nautilus_srm_fill_operation_filter_files (GList *paths,
+ GList **work_paths_,
+ GList **work_mounts_,
+ GError **error)
{
- GList *dirs = NULL;
- GError *err = NULL;
- /* table of different mountpoints */
- GHashTable *mountpoints = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, NULL);
+ GList *work_paths = NULL;
+ GError *err = NULL;
+ GList *work_mounts = NULL;
- g_return_val_if_fail (directories != NULL, NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail (paths != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- for (; ! err && directories; directories = g_list_next (directories)) {
- const gchar *file_path = directories->data;
+ for (; ! err && paths; paths = g_list_next (paths)) {
+ const gchar *file_path = paths->data;
gchar *mountpoint;
mountpoint = find_mountpoint (file_path, &err);
if (G_LIKELY (mountpoint)) {
- if (g_hash_table_lookup (mountpoints, mountpoint)) {
+ if (g_list_find_custom (work_mounts, mountpoint, g_str_equal)) {
/* the mountpoint is already added, skip it */
g_free (mountpoint);
} else {
gchar *path;
- g_hash_table_insert (mountpoints, mountpoint, (gpointer)TRUE);
+ work_mounts = g_list_append (work_mounts, mountpoint);
/* 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 */
@@ -307,28 +315,31 @@ filter_dir_list (GList *directories,
} else {
path = g_strdup (file_path);
}
- dirs = g_list_append (dirs, path);
+ work_paths = g_list_append (work_paths, path);
}
}
}
- g_hash_table_destroy (mountpoints);
+ if (err || ! work_paths_) {
+ nautilus_srm_path_list_free (work_paths);
+ } else {
+ *work_paths_ = work_paths;
+ }
+ if (err || ! work_mounts_) {
+ nautilus_srm_path_list_free (work_mounts);
+ } else {
+ *work_mounts_ = work_mounts;
+ }
if (err) {
- while (dirs) {
- GList *tmp = dirs;
-
- dirs = g_list_next (dirs);
- g_free (tmp->data);
- g_list_free_1 (tmp);
- }
g_propagate_error (error, err);
}
- return dirs;
+ return ! err;
}
/*
* nautilus_srm_fill_operation:
- * @directories: A list of paths to work on
+ * @directories: A list of paths to work on (should have been filtered with
+ * nautilus_srm_fill_operation_filter_files() or so)
* @fast: The Gsd.SecureDeleteOperation:fast setting
* @mode: The Gsd.SecureDeleteOperation:mode setting
* @zeroise: The Gsd.ZeroableOperation:zeroise setting
@@ -360,7 +371,7 @@ nautilus_srm_fill_operation (GList *directories,
g_return_val_if_fail (directories != NULL, NULL);
- dirs = filter_dir_list (directories, error);
+ dirs = nautilus_srm_path_list_copy (directories);
if (dirs) {
opdata = g_slice_alloc (sizeof *opdata);
opdata->dir = dirs;
diff --git a/nautilus-srm/fill-operation.h b/nautilus-srm/fill-operation.h
index 523c2c0..5d20181 100644
--- a/nautilus-srm/fill-operation.h
+++ b/nautilus-srm/fill-operation.h
@@ -29,6 +29,10 @@
G_BEGIN_DECLS
+gboolean nautilus_srm_fill_operation_filter_files (GList *paths,
+ GList **work_paths_,
+ GList **work_mounts_,
+ GError **error);
GsdAsyncOperation *nautilus_srm_fill_operation (GList *files,
gboolean fast,
GsdSecureDeleteOperationMode mode,
diff --git a/nautilus-srm/nautilus-srm.c b/nautilus-srm/nautilus-srm.c
index cb855f2..632a6fe 100644
--- a/nautilus-srm/nautilus-srm.c
+++ b/nautilus-srm/nautilus-srm.c
@@ -171,7 +171,8 @@ nautilus_srm_register_type (GTypeModule *module)
/*=== Actual extension ===*/
static void run_fill_operation (GtkWindow *parent,
- GList *files);
+ GList *paths,
+ GList *mountpoints);
static void run_delete_operation (GtkWindow *parent,
GList *files);
@@ -236,7 +237,7 @@ nautilus_srm_nfi_get_path (NautilusFileInfo *nfi)
}
/* frees a list of paths */
-static void
+void
nautilus_srm_path_list_free (GList *paths)
{
while (paths) {
@@ -250,7 +251,7 @@ nautilus_srm_path_list_free (GList *paths)
/* copies a list of paths
* free the returned list with nautilus_srm_path_list_free() */
-static GList *
+GList *
nautilus_srm_path_list_copy (GList *src)
{
GList *paths = NULL;
@@ -300,11 +301,12 @@ nautilus_srm_nfi_list_to_path_list (GList *nfis)
* operations to the same window rather than the one that launched it. */
struct ItemData
{
- GtkWindow *window; /* parent window
- * 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 *paths; /* list of selected paths */
+ GtkWindow *window; /* parent window
+ * 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 *paths; /* list of selected paths */
+ GList *mountpoints; /* list of selected mountpoints, used by fill op */
};
/* Frees an #ItemData */
@@ -312,6 +314,7 @@ static void
item_data_free (struct ItemData *idata)
{
nautilus_srm_path_list_free (idata->paths);
+ nautilus_srm_path_list_free (idata->mountpoints);
g_slice_free1 (sizeof *idata, idata);
}
@@ -322,7 +325,8 @@ item_data_free (struct ItemData *idata)
static void
add_item_data (NautilusMenuItem *item,
GtkWidget *window,
- GList *paths)
+ GList *paths,
+ GList *mountpoints)
{
struct ItemData *idata;
@@ -332,6 +336,7 @@ add_item_data (NautilusMenuItem *item,
* not (even be able to) activate our button. */
idata->window = GTK_IS_WINDOW (window) ? GTK_WINDOW (window) : NULL;
idata->paths = nautilus_srm_path_list_copy (paths);
+ idata->mountpoints = nautilus_srm_path_list_copy (mountpoints);
g_object_set_data_full (G_OBJECT (item), "NautilusSrm::item-data",
idata, (GDestroyNotify)item_data_free);
}
@@ -368,7 +373,7 @@ nautilus_srm_menu_item_srm (NautilusMenuProvider *provider,
_("Wipe"),
_("Delete each selected item, and overwrite its data"),
GTK_STOCK_DELETE);
- add_item_data (item, window, paths);
+ add_item_data (item, window, paths, NULL);
g_signal_connect (item, "activate",
G_CALLBACK (menu_item_delete_activate_handler), provider);
@@ -382,28 +387,49 @@ menu_item_fill_activate_handler (NautilusMenuItem *item,
{
struct ItemData *idata = get_item_data (item);
- run_fill_operation (idata->window, idata->paths);
+ run_fill_operation (idata->window, idata->paths, idata->mountpoints);
}
static NautilusMenuItem *
nautilus_srm_menu_item_sfill (NautilusMenuProvider *provider,
const gchar *item_name,
GtkWidget *window,
- GList *folders)
+ GList *files)
{
- NautilusMenuItem *item;
-
- item = nautilus_menu_item_new (item_name,
- _("Wipe available diskspace"),
- _("Overwrite available diskspace in this device(s)"),
- NULL);
- add_item_data (item, window, folders);
- g_signal_connect (item, "activate",
- G_CALLBACK (menu_item_fill_activate_handler), provider);
+ NautilusMenuItem *item = NULL;
+ GList *mountpoints = NULL;
+ GList *folders = NULL;
+ GError *err = NULL;
+
+ if (! nautilus_srm_fill_operation_filter_files (files, &folders, &mountpoints,
+ &err)) {
+ g_warning ("File filtering failed: %s", err->message);
+ g_error_free (err);
+ } else {
+ item = nautilus_menu_item_new (item_name,
+ _("Wipe available diskspace"),
+ _("Overwrite available diskspace in this device(s)"),
+ NULL);
+ add_item_data (item, window, folders, mountpoints);
+ g_signal_connect (item, "activate",
+ G_CALLBACK (menu_item_fill_activate_handler), provider);
+ nautilus_srm_path_list_free (folders);
+ nautilus_srm_path_list_free (mountpoints);
+ }
return item;
}
+/* adds @item to the #GList @items if not %NULL */
+#define ADD_ITEM(items, item) \
+ G_STMT_START { \
+ NautilusMenuItem *ADD_ITEM__item = (item); \
+ \
+ if (ADD_ITEM__item != NULL) { \
+ items = g_list_append (items, ADD_ITEM__item); \
+ } \
+ } G_STMT_END
+
/* populates Nautilus' file menu */
static GList *
nautilus_srm_get_file_items (NautilusMenuProvider *provider,
@@ -415,12 +441,12 @@ nautilus_srm_get_file_items (NautilusMenuProvider *provider,
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, paths));
- items = g_list_append (items, nautilus_srm_menu_item_sfill (provider,
- "nautilus-srm::files-items::sfill",
- window, paths));
+ ADD_ITEM (items, nautilus_srm_menu_item_srm (provider,
+ "nautilus-srm::files-items::srm",
+ window, paths));
+ ADD_ITEM (items, nautilus_srm_menu_item_sfill (provider,
+ "nautilus-srm::files-items::sfill",
+ window, paths));
}
nautilus_srm_path_list_free (paths);
@@ -438,15 +464,16 @@ nautilus_srm_get_background_items (NautilusMenuProvider *provider,
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));
+ ADD_ITEM (items, nautilus_srm_menu_item_sfill (provider,
+ "nautilus-srm::background-items::sfill",
+ window, paths));
}
nautilus_srm_path_list_free (paths);
return items;
}
+#undef ADD_ITEM
/* Runs the srm operation */
@@ -493,14 +520,15 @@ run_delete_operation (GtkWindow *parent,
/* Runs the sfill operation */
static void
run_fill_operation (GtkWindow *parent,
- GList *files)
+ GList *paths,
+ GList *mountpoints)
{
gchar *confirm_primary_text = NULL;
guint n_items;
/* XXX: we want
n_items = g_list_length (mountpoints);*/
- n_items = g_list_length (files);
+ n_items = g_list_length (mountpoints);
/* FIXME: can't truly use g_dngettext since the args are not the same */
if (n_items > 1) {
/* XXX: precise the devices to sfill (name:=device name):
@@ -525,7 +553,7 @@ run_fill_operation (GtkWindow *parent,
} else if (n_items > 0) {
gchar *name;
- name = g_filename_display_basename (files->data);
+ name = g_filename_display_basename (mountpoints->data);
/* XXX: precise the devices to sfill (name:=device name):
g_strdup_printf (_("Are you sure you want to wipe "
"the available diskspace on the "
@@ -538,7 +566,7 @@ run_fill_operation (GtkWindow *parent,
g_free (name);
}
nautilus_srm_operation_manager_run (
- parent, files,
+ parent, paths,
/* confirm dialog */
confirm_primary_text,
_("This operation may take a while."),
diff --git a/nautilus-srm/nautilus-srm.h b/nautilus-srm/nautilus-srm.h
index 5630702..e2c0cbf 100644
--- a/nautilus-srm/nautilus-srm.h
+++ b/nautilus-srm/nautilus-srm.h
@@ -65,8 +65,12 @@ struct _NautilusSrmClass {
GObjectClass parent_slot;
};
-GType nautilus_srm_get_type (void) G_GNUC_CONST;
-GQuark nautilus_srm_error_quark (void) G_GNUC_CONST;
+GType nautilus_srm_get_type (void) G_GNUC_CONST;
+GQuark nautilus_srm_error_quark (void) G_GNUC_CONST;
+
+void nautilus_srm_path_list_free (GList *paths);
+GList *nautilus_srm_path_list_copy (GList *src);
+
G_END_DECLS
--
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