summaryrefslogtreecommitdiff
path: root/zen/recycler.cpp
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-08-31 20:07:13 -0400
committerB Stack <bgstack15@gmail.com>2020-08-31 20:07:13 -0400
commit8a27fa9c617533e76673ce61a65e2ba869b52208 (patch)
treeacfdfb3e1046db87040477033fda0df76d92916a /zen/recycler.cpp
parentMerge branch '11.0' into 'master' (diff)
downloadFreeFileSync-8a27fa9c617533e76673ce61a65e2ba869b52208.tar.gz
FreeFileSync-8a27fa9c617533e76673ce61a65e2ba869b52208.tar.bz2
FreeFileSync-8a27fa9c617533e76673ce61a65e2ba869b52208.zip
add upstream 11.1
Diffstat (limited to 'zen/recycler.cpp')
-rw-r--r--zen/recycler.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/zen/recycler.cpp b/zen/recycler.cpp
index 9c463546..b1f2c0fd 100644
--- a/zen/recycler.cpp
+++ b/zen/recycler.cpp
@@ -11,7 +11,6 @@
#include <gio/gio.h>
#include "scope_guard.h"
-
using namespace zen;
@@ -31,8 +30,15 @@ bool zen::recycleOrDeleteIfExists(const Zstring& itemPath) //throw FileError
if (!type)
return false;
- //implement same behavior as in Windows: if recycler is not existing, delete permanently
- if (error && error->code == G_IO_ERROR_NOT_SUPPORTED)
+ /* g_file_trash() can fail with different error codes/messages when trash is unavailable:
+ Debian 8 (GLib 2.42): G_IO_ERROR_NOT_SUPPORTED: Unable to find or create trash directory
+ CentOS 7 (GLib 2.56): G_IO_ERROR_FAILED: Unable to find or create trash directory for file.txt
+ master (GLib 2.64): G_IO_ERROR_NOT_SUPPORTED: Trashing on system internal mounts is not supported
+ https://gitlab.gnome.org/GNOME/glib/blob/master/gio/glocalfile.c#L2042 */
+ const bool trashUnavailable = error &&
+ ((error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_SUPPORTED) ||
+ startsWith(error->message, "Unable to find or create trash directory"));
+ if (trashUnavailable) //implement same behavior as on Windows: if recycler is not existing, delete permanently
{
if (*type == ItemType::folder)
removeDirectoryPlainRecursion(itemPath); //throw FileError
@@ -42,13 +48,9 @@ bool zen::recycleOrDeleteIfExists(const Zstring& itemPath) //throw FileError
}
throw FileError(replaceCpy(_("Unable to move %x to the recycle bin."), L"%x", fmtPath(itemPath)),
- formatSystemError("g_file_trash",
- error ? replaceCpy(_("Error code %x"), L"%x", numberTo<std::wstring>(error->code)) : L"",
- error ? utfTo<std::wstring>(error->message) : L"Unknown error."));
- //g_quark_to_string(error->domain)
+ formatGlibError("g_file_trash", error));
}
return true;
-
}
bgstack15