From: Colin Clark Date: Sun, 26 Mar 2023 17:53:05 +0000 (+0100) Subject: Ref #1025: "Move to trash" does not do anything (cross-filesystem) X-Git-Tag: v2.1~86 X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?p=geeqie.git;a=commitdiff_plain;h=97d4bb2938f9ecbd245363ae092989666b1545ba Ref #1025: "Move to trash" does not do anything (cross-filesystem) https://github.com/BestImageViewer/geeqie/issues/1025 Co-authored-by: BecauseTheWorldIsRound - A warning dialog is displayed if trash fails - A workaround is documented --- diff --git a/doc/docbook/GuideFaq.xml b/doc/docbook/GuideFaq.xml index 2766946e..e267e14f 100644 --- a/doc/docbook/GuideFaq.xml +++ b/doc/docbook/GuideFaq.xml @@ -2,6 +2,45 @@ Frequently Asked Questions +
+ Move to Trash failed + +
+ How do I fix move to trash failed? + It appears that some distributions will only trash files that are in the same filesytem as where the Trash bin is located. + + The location of the Trash bin for some systems is + $HOME/.local/share/Trash + . + + + If you attempt to trash a file not in this filesystem, an attempt is made to find directory + <top of filesystem>/.Trash-<uid> + where + <uid> + is your user id (in a terminal type + id + to display it). If this directory does not exist, then the action will fail. + + You may create this directory and set write access to it as follows: + + + cd + to the directory where the file to be deleted is + + df --human-readable . + (Note the dot!) The "Mounted on" column shows the top of the filesystem. + + cd <the top of the filesystem shown above> + + sudo mkdir .Trash-<uid> + + sudo chown <your user name> .Trash-<uid> + + sudo chmod u+rwx .Trash-<uid> + +
+
Image viewing diff --git a/src/trash.cc b/src/trash.cc index eaa31fc2..6557c33f 100644 --- a/src/trash.cc +++ b/src/trash.cc @@ -22,6 +22,7 @@ #include "main.h" #include "trash.h" #include "utilops.h" +#include "window.h" #include "editors.h" #include "filedata.h" @@ -116,11 +117,17 @@ static gchar *file_util_safe_dest(const gchar *path) return dest; } +static void move_to_trash_failed_cb(GenericDialog *UNUSED(gd), gpointer UNUSED(data)) +{ + help_window_show("TrashFailed.html"); +} + gboolean file_util_safe_unlink(const gchar *path) { static GenericDialog *gd = NULL; gchar *result = NULL; gboolean success = TRUE; + gchar *message; if (!isfile(path)) return FALSE; @@ -179,10 +186,22 @@ gboolean file_util_safe_unlink(const gchar *path) } else { - GFile *tmp = g_file_new_for_path (path); - g_file_trash(tmp, FALSE, NULL); - g_object_unref(tmp); - } + GFile *tmp = g_file_new_for_path(path); + GError *error = NULL; + + if (!g_file_trash(tmp, FALSE, &error) ) + { + message = g_strconcat("See the Help file for a possible workaround.\n\n", error->message, NULL); + gd = warning_dialog(_("Move to trash failed\n\n"), message, GTK_STOCK_DIALOG_ERROR, NULL); + generic_dialog_add_button(gd, GTK_STOCK_HELP, "Help", move_to_trash_failed_cb, FALSE); + + g_free(message); + g_error_free(error); + + /* A second warning dialog is not necessary */ + // success = FALSE; + } + } return success; }