[Pkg-privacy-commits] [nautilus-wipe] 24/224: Add the two possible operations implementation.
Ulrike Uhlig
u-guest at moszumanska.debian.org
Thu Jul 7 19:45:30 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 aaa5af037ee9f06ee53e54cc9c7cbf9f698d8357
Author: Colomban Wendling <ban at herbesfolles.org>
Date: Tue Feb 16 20:29:59 2010 +0100
Add the two possible operations implementation.
Not used for now, untested implementations of fill and delete
operations.
---
configure.ac | 14 +-
nautilus-srm/Makefile.am | 2 +
nautilus-srm/delete-operation.c | 85 +++++++++++
nautilus-srm/fill-operation.c | 323 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 422 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 851d434..cd52486 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,10 +35,20 @@ PKG_CHECK_MODULES([NAUTILUS_SRM], \
gsecuredelete >= ${GSECUREDELETE_REQUIRED} \
)
+GIO_UNIX_REQUIRED=2.0
+
+HAVE_GIO_UNIX=0
+PKG_CHECK_MODULES([GIO_UNIX], gio-unix-2.0 >= ${GIO_UNIX_REQUIRED},
+ [ HAVE_GIO_UNIX=1
+ AC_SUBST([GIO_UNIX_CFLAGS])
+ AC_SUBST([GIO_UNIX_LIBS]) ],
+ [ echo " $GIO_UNIX_PKG_ERRORS">&2 ])
+AC_DEFINE_UNQUOTED([HAVE_GIO_UNIX], [${HAVE_GIO_UNIX}], [Whether we have gio-unix])
+
AC_SUBST([NAUTILUS_SRM_CFLAGS])
AC_SUBST([NAUTILUS_SRM_LIBS])
-AC_SUBST([AM_CFLAGS],["${AM_CFLAGS} ${NAUTILUS_SRM_CFLAGS}"])
-AC_SUBST([AM_LIBS],["${AM_LIBS} ${NAUTILUS_SRM_LIBS}"])
+AC_SUBST([AM_CFLAGS],["${AM_CFLAGS} ${NAUTILUS_SRM_CFLAGS} ${GIO_UNIX_CFLAGS}"])
+AC_SUBST([AM_LIBS],["${AM_LIBS} ${NAUTILUS_SRM_LIBS} ${GIO_UNIX_LIBS}"])
# i18n
AM_GNU_GETTEXT([external])
diff --git a/nautilus-srm/Makefile.am b/nautilus-srm/Makefile.am
index d1b0934..c286903 100644
--- a/nautilus-srm/Makefile.am
+++ b/nautilus-srm/Makefile.am
@@ -3,6 +3,8 @@ nautilus_extensiondir = $(NAUTILUS_EXTENSIONS_DIR)
nautilus_extension_LTLIBRARIES = libnautilus-srm.la
libnautilus_srm_la_SOURCES = nautilus-srm.c \
+ delete-operation.c \
+ fill-operation.c \
nautilus-srm.h
libnautilus_srm_la_LDFLAGS = $(AM_LIBS) -module -avoid-version
diff --git a/nautilus-srm/delete-operation.c b/nautilus-srm/delete-operation.c
new file mode 100644
index 0000000..347d2e5
--- /dev/null
+++ b/nautilus-srm/delete-operation.c
@@ -0,0 +1,85 @@
+/*
+ * nautilus-srm - a nautilus extension to wipe file(s) with srm
+ *
+ * Copyright (C) 2009-2010 Colomban Wendling <ban at herbesfolles.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <gsecuredelete/gsecuredelete.h>
+#include <libnautilus-extension/nautilus-file-info.h>
+
+
+/*
+ * nsrm_delete_operation:
+ * @files: A list of #NautilusFileInfo to delete.
+ * @finished_handler: A handler for GsdAsyncOperation::finished
+ * @progress_handler: A handler for GsdAsyncOperation::progress
+ * @data: User data to pass to @finished_handler and @progress_handler
+ * @error: Return location for errors or %NULL to ignore them. The errors are
+ * those from gsd_secure_delete_operation_run().
+ *
+ * Deletes the given files with libgsecuredelete.
+ *
+ * Returns: %TRUE if operation successfully started, %FALSE otherwise. %TRUE
+ * does not mean that anything was actually done, but only that the
+ * operation started successfully.
+ */
+gboolean
+nautilus_srm_delete_operation (GList *files,
+ GCallback finished_handler,
+ GCallback progress_handler,
+ gpointer data,
+ GError **error)
+{
+ gboolean success;
+ GsdDeleteOperation *operation;
+
+ operation = gsd_delete_operation_new ();
+ for (; 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) {
+ /* FIXME: */
+ } else {
+ gsd_delete_operation_add_path (operation, path);
+ }
+ g_free (path);
+ g_object_unref (file);
+ }
+
+ g_signal_connect (operation, "progress", progress_handler, data);
+ g_signal_connect (operation, "finished", finished_handler, data);
+ /* unrefs the operation when done (notice that it is called after the default
+ * handler) */
+ g_signal_connect_after (operation, "finished",
+ G_CALLBACK (g_object_unref), NULL);
+ success = gsd_secure_delete_operation_run (GSD_SECURE_DELETE_OPERATION (operation),
+ 100, error);
+ if (! success) {
+ /* on failure here the callback will not be called, then unref right here */
+ g_object_unref (operation);
+ }
+
+ return success;
+}
+
diff --git a/nautilus-srm/fill-operation.c b/nautilus-srm/fill-operation.c
new file mode 100644
index 0000000..7eebe47
--- /dev/null
+++ b/nautilus-srm/fill-operation.c
@@ -0,0 +1,323 @@
+/*
+ * nautilus-srm - a nautilus extension to wipe file(s) with srm
+ *
+ * Copyright (C) 2009-2010 Colomban Wendling <ban at herbesfolles.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <gio/gio.h>
+#if HAVE_GIO_UNIX
+# include <gio/gunixmounts.h>
+#endif
+
+#include <gsecuredelete/gsecuredelete.h>
+#include <libnautilus-extension/nautilus-file-info.h>
+
+
+#if HAVE_GIO_UNIX
+/*
+ * find_mountpoint_unix:
+ * @path: An absolute path for which find the mountpoint.
+ *
+ * Gets the UNIX mountpoint path of a given path.
+ * <note>
+ * This function would actually never return %NULL since the mount point of
+ * every files is at least /.
+ * </note>
+ *
+ * Returns: The path of the mountpoint of @path or %NULL if not found.
+ * Free with g_free().
+ */
+static gchar *
+find_mountpoint_unix (const gchar *path)
+{
+ gchar *mountpoint = g_strdup (path);
+ gboolean found = FALSE;
+
+ while (! found && mountpoint) {
+ GUnixMountEntry *unix_mount;
+
+ //~ g_debug ("trying %s", mountpoint);
+ unix_mount = g_unix_mount_at (mountpoint, NULL);
+ if (unix_mount) {
+ found = TRUE;
+ g_unix_mount_free (unix_mount);
+ } else {
+ gchar *tmp = mountpoint;
+
+ mountpoint = g_path_get_dirname (tmp);
+ /* check if dirname() changed the path to avoid infinite loop (e.g. when
+ * / was reached) */
+ if (strcmp (mountpoint, tmp) == 0) {
+ g_free (mountpoint);
+ mountpoint = NULL;
+ }
+ g_free (tmp);
+ }
+ }
+
+ return mountpoint;
+}
+#endif
+
+static gchar *
+find_mountpoint (GFile *file)
+{
+ gchar *mountpoint_path = NULL;
+ GMount *mount;
+
+ /* Try with GIO first */
+ mount = g_file_find_enclosing_mount (file, NULL, NULL);
+ if (mount) {
+ GFile *mountpoint_file;
+
+ mountpoint_file = g_mount_get_root (mount);
+ mountpoint_path = g_file_get_path (mountpoint_file);
+ g_object_unref (mountpoint_file);
+ g_object_unref (mount);
+ }
+ #if HAVE_GIO_UNIX
+ /* fallback to find_unix_mount() */
+ if (! mountpoint_path) {
+ gchar *path = g_file_get_path (file);
+
+ if (path) {
+ mountpoint_path = find_mountpoint_unix (path);
+ }
+ g_free (path);
+ }
+ #endif
+
+ return mountpoint_path;
+}
+
+
+typedef void (*FillFinishedFunc) (GsdFillOperation *self,
+ gboolean success,
+ const gchar *message,
+ gpointer data);
+typedef void (*FillProgressFunc) (GsdFillOperation *self,
+ gdouble fraction,
+ gpointer data);
+/* The data structure that holds the operation state and data */
+struct FillOperationData
+{
+ GsdFillOperation *operation;
+ /* the current directory to work on (dir->data) */
+ GList *dir;
+ /* GObject's signals handlers IDs */
+ gulong finished_hid;
+ gulong progress_hid;
+ /* operation status */
+ guint n_op;
+ guint n_op_done;
+
+ /* caller's handlers for wrapping */
+ FillFinishedFunc finished_handler;
+ FillProgressFunc progress_handler;
+ gpointer cbdata;
+};
+
+/* Actually calls libgsecuredelete */
+static gboolean
+do_sfill_operation (struct FillOperationData *opdata,
+ GError **error)
+{
+ /* FIXME: don't launch sfill in a useful directory since it can leave a bunch
+ * of files if it get interrupted (e.g. from a crash, a user kill or so) */
+ return gsd_fill_operation_run (opdata->operation, opdata->dir->data, 100, error);
+}
+
+/* Removes the current directory to proceed */
+static void
+nautilus_srm_fill_pop_dir (struct FillOperationData *opdata)
+{
+ GList *tmp;
+
+ tmp = opdata->dir;
+ opdata->dir = g_list_next (opdata->dir);
+ g_free (tmp->data);
+ g_list_free_1 (tmp);
+}
+
+/* Cleans up the opdata structure and frees it */
+static void
+nautilus_srm_fill_cleanup (struct FillOperationData *opdata)
+{
+ g_signal_handler_disconnect (opdata->operation, opdata->progress_hid);
+ g_signal_handler_disconnect (opdata->operation, opdata->finished_hid);
+ g_object_unref (opdata->operation);
+ while (opdata->dir) {
+ nautilus_srm_fill_pop_dir (opdata);
+ }
+ g_slice_free1 (sizeof *opdata, opdata);
+}
+
+/* wrapper for the progress handler returning the current progression over all
+ * operations */
+static void
+nautilus_srm_fill_progress_handler (GsdFillOperation *operation,
+ gdouble fraction,
+ struct FillOperationData *opdata)
+{
+ opdata->progress_handler (operation,
+ (opdata->n_op_done + fraction) / opdata->n_op,
+ opdata->cbdata);
+}
+
+/* Wrapper for the finished handler.
+ * It launches the next operation if there is one left, or call the user's
+ * handler if done or on error. */
+static void
+nautilus_srm_fill_finished_handler (GsdFillOperation *operation,
+ gboolean success,
+ const gchar *message,
+ struct FillOperationData *opdata)
+{
+ gboolean free_message = FALSE; /* hack to be able to fill @message */
+
+ opdata->n_op_done++;
+ /* remove the directory just proceeded */
+ nautilus_srm_fill_pop_dir (opdata);
+ /* if the last operation succeeded and we have work left */
+ if (success && opdata->dir) {
+ GError *err = NULL;
+
+ success = do_sfill_operation (opdata, &err);
+ if (! success) {
+ message = g_strdup (err->message);
+ free_message = TRUE;
+ g_error_free (err);
+ }
+ }
+ if (! success || ! opdata->dir) {
+ opdata->finished_handler (operation, success, message, opdata->cbdata);
+ nautilus_srm_fill_cleanup (opdata);
+ }
+ if (free_message) {
+ g_free ((gchar *)message);
+ }
+}
+
+/*
+ * filter_dir_list:
+ * @directories: a list of #NautilusFileInfo
+ *
+ * Filter the input file list so that there remains only one path for
+ * each filesystem.
+ *
+ * Returns: A #GList of file pathes to actually work on. Free each element with
+ * g_free() before freeing the list.
+ */
+static GList *
+filter_dir_list (GList *directories)
+{
+ GList *dirs = NULL;
+ /* table of different mountpoints */
+ GHashTable *mountpoints = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, NULL);
+
+ for (; directories; directories = g_list_next (directories)) {
+ GFile *file = nautilus_file_info_get_location (directories->data);
+ gchar *mountpoint;
+
+ mountpoint = find_mountpoint (file);
+ if (G_UNLIKELY (! mountpoint)) {
+ /* FIXME: do something even if this is very unlikely */
+ gchar *uri = g_file_get_uri (file);
+
+ g_warning ("Cannot find mountpoint of URI %s, skipping", uri);
+ g_free (uri);
+ } else {
+ if (g_hash_table_lookup (mountpoints, mountpoint)) {
+ /* the mountpoint is already added, skip it */
+ g_free (mountpoint);
+ } else {
+ gchar *path;
+
+ g_hash_table_insert (mountpoints, mountpoint, NULL);
+ path = g_file_get_path (file);
+ if (! path) {
+ /* FIXME: do something (it is probably a remote file)
+ * hum, I think it can't happen since find_mountpoint() would fail
+ * on remote files */
+ gchar *uri = g_file_get_uri (file);
+
+ g_warning ("Cannot get path for URI %s, skipping", uri);
+ g_free (uri);
+ } else {
+ dirs = g_list_append (dirs, path);
+ }
+ }
+ }
+ g_object_unref (file);
+ }
+ g_hash_table_destroy (mountpoints);
+
+ return dirs;
+}
+
+/*
+ * nautilus_srm_fill_operation:
+ * @directories: A list of #NautilusFileInfo to work on
+ * @finished_handler: A handler for GsdAsyncOperation::finished
+ * @progress_handler: A handler for GsdAsyncOperation::progress
+ * @data: User data to pass to @finished_handler and @progress_handler
+ * @error: Return location for errors or %NULL to ignore them. The errors are
+ * those from gsd_fill_operation_run().
+ *
+ * "sfill"s the given directories.
+ *
+ * Returns: %TRUE if operation successfully started, %FALSE otherwise. %TRUE
+ * does not mean that anything was actually done, but only that the
+ * operation started successfully.
+ */
+gboolean
+nautilus_srm_fill_operation (GList *directories,
+ GCallback finished_handler,
+ GCallback progress_handler,
+ gpointer data,
+ GError **error)
+{
+ gboolean success = TRUE;
+ struct FillOperationData *opdata;
+
+ opdata = g_slice_alloc (sizeof *opdata);
+ opdata->dir = filter_dir_list (directories);
+ opdata->finished_handler = (FillFinishedFunc)finished_handler;
+ opdata->progress_handler = (FillProgressFunc)progress_handler;
+ opdata->cbdata = data;
+ opdata->n_op = g_list_length (opdata->dir);
+ opdata->n_op_done = 0;
+ opdata->operation = gsd_fill_operation_new ();
+ opdata->progress_hid = g_signal_connect (opdata->operation, "progress",
+ G_CALLBACK (nautilus_srm_fill_progress_handler), opdata);
+ opdata->finished_hid = g_signal_connect (opdata->operation, "finished",
+ G_CALLBACK (nautilus_srm_fill_finished_handler), opdata);
+ /* launches the operation */
+ success = do_sfill_operation (opdata, error);
+ if (! success) {
+ nautilus_srm_fill_cleanup (opdata);
+ }
+
+ return success;
+}
+
--
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