Ref #1025: "Move to trash" does not do anything (cross-filesystem)
authorColin Clark <colin.clark@cclark.uk>
Sun, 26 Mar 2023 17:53:05 +0000 (18:53 +0100)
committerColin Clark <colin.clark@cclark.uk>
Sun, 26 Mar 2023 17:53:05 +0000 (18:53 +0100)
https://github.com/BestImageViewer/geeqie/issues/1025

Co-authored-by: BecauseTheWorldIsRound
- A warning dialog is displayed if trash fails
- A workaround is documented

doc/docbook/GuideFaq.xml
src/trash.cc

index 2766946..e267e14 100644 (file)
@@ -2,6 +2,45 @@
 <chapter id="GuideFaq">
   <title>Frequently Asked Questions</title>
   <para />
+  <section id="TrashFailed">
+    <title>Move to Trash failed</title>
+    <para />
+    <section id="HowdoIfixtrashproblem">
+      <title>How do I fix move to trash failed?</title>
+      <para>It appears that some distributions will only trash files that are in the same filesytem as where the Trash bin is located.</para>
+      <para>
+        The location of the Trash bin for some systems is
+        <code>$HOME/.local/share/Trash</code>
+        .
+      </para>
+      <para>
+        If you attempt to trash a file not in this filesystem, an attempt is made to find directory
+        <code>&lt;top of filesystem&gt;/.Trash-&lt;uid&gt;</code>
+        where
+        <code>&lt;uid&gt;</code>
+        is your user id (in a terminal type
+        <code>id</code>
+        to display it). If this directory does not exist, then the action will fail.
+      </para>
+      <para>You may create this directory and set write access to it as follows:</para>
+      <para />
+      <para>
+        <code>cd</code>
+        to the directory where the file to be deleted is
+        <para />
+        <code>df --human-readable .</code>
+        (Note the dot!) The "Mounted on" column shows the top of the filesystem.
+        <para />
+        <code>cd &lt;the top of the filesystem shown above&gt;</code>
+        <para />
+        <code>sudo mkdir .Trash-&lt;uid&gt;</code>
+        <para />
+        <code>sudo chown &lt;your user name&gt; .Trash-&lt;uid&gt;</code>
+        <para />
+        <code>sudo chmod u+rwx .Trash-&lt;uid&gt;</code>
+      </para>
+    </section>
+  </section>
   <section id="Imageviewing">
     <title>Image viewing</title>
     <para />
index eaa31fc..6557c33 100644 (file)
@@ -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;
 }