summaryrefslogtreecommitdiff
path: root/zen/recycler.cpp
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-10-11 15:17:59 +0000
committerB. Stack <bgstack15@gmail.com>2022-10-11 15:17:59 +0000
commit38c826621a39831d1bdc78aa9e45cc592db3e77f (patch)
treea49cfd729d9793681a57fa6f7409b0f0848e9ede /zen/recycler.cpp
parentMerge branch 'b11.25' into 'master' (diff)
parentadd upstream 11.26 (diff)
downloadFreeFileSync-38c826621a39831d1bdc78aa9e45cc592db3e77f.tar.gz
FreeFileSync-38c826621a39831d1bdc78aa9e45cc592db3e77f.tar.bz2
FreeFileSync-38c826621a39831d1bdc78aa9e45cc592db3e77f.zip
Merge branch 'b11.26' into 'master'11.26
add upstream 11.26 See merge request opensource-tracking/FreeFileSync!49
Diffstat (limited to 'zen/recycler.cpp')
-rw-r--r--zen/recycler.cpp39
1 files changed, 5 insertions, 34 deletions
diff --git a/zen/recycler.cpp b/zen/recycler.cpp
index 4448fd60..26c27952 100644
--- a/zen/recycler.cpp
+++ b/zen/recycler.cpp
@@ -5,9 +5,7 @@
// *****************************************************************************
#include "recycler.h"
-#include "file_access.h"
- #include <sys/stat.h>
#include <gio/gio.h>
#include "scope_guard.h"
@@ -17,7 +15,7 @@ using namespace zen;
//*INDENT-OFF*
-bool zen::recycleOrDeleteIfExists(const Zstring& itemPath) //throw FileError
+void zen::moveToRecycleBin(const Zstring& itemPath) //throw FileError, RecycleBinUnavailable
{
GFile* file = ::g_file_new_for_path(itemPath.c_str()); //never fails according to docu
ZEN_ON_SCOPE_EXIT(g_object_unref(file);)
@@ -27,10 +25,6 @@ bool zen::recycleOrDeleteIfExists(const Zstring& itemPath) //throw FileError
if (!::g_file_trash(file, nullptr, &error))
{
- const std::optional<ItemType> type = itemStillExists(itemPath); //throw FileError
- if (!type)
- return false;
-
/* 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 => localized! >:(
@@ -42,7 +36,7 @@ bool zen::recycleOrDeleteIfExists(const Zstring& itemPath) //throw FileError
//yes, the following is a cluster fuck, but what can you do?
(error->code == G_IO_ERROR_FAILED && [&]
{
- for (const char* msgLoc : //translations from https://gitlab.gnome.org/GNOME/glib/-/tree/master/po
+ for (const char* msgLoc : //translations from https://gitlab.gnome.org/GNOME/glib/-/tree/main/po
{
"Unable to find or create trash directory for",
"No s'ha pogut trobar o crear el directori de la paperera per",
@@ -100,35 +94,12 @@ bool zen::recycleOrDeleteIfExists(const Zstring& itemPath) //throw FileError
return false;
}()));
- if (trashUnavailable) //implement same behavior as on Windows: if recycler is not existing, delete permanently
- {
- if (*type == ItemType::folder)
- removeDirectoryPlainRecursion(itemPath); //throw FileError
- else
- removeFilePlain(itemPath); //throw FileError
- return true;
- }
+ if (trashUnavailable)
+ throw RecycleBinUnavailable(replaceCpy(_("The recycle bin is not available for %x."), L"%x", fmtPath(itemPath)),
+ formatGlibError("g_file_trash", error));
throw FileError(replaceCpy(_("Unable to move %x to the recycle bin."), L"%x", fmtPath(itemPath)),
formatGlibError("g_file_trash", error));
}
- return true;
}
//*INDENT-ON*
-
-
-/* We really need access to a similar function to check whether a directory supports trashing and emit a warning if it does not!
-
- The following function looks perfect, alas it is restricted to local files and to the implementation of GIO only:
-
- gboolean _g_local_file_has_trash_dir(const char* dirpath, dev_t dir_dev);
- See: http://www.netmite.com/android/mydroid/2.0/external/bluetooth/glib/gio/glocalfileinfo.h
-
- Just checking for "G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH" is not correct, since we find in
- http://www.netmite.com/android/mydroid/2.0/external/bluetooth/glib/gio/glocalfileinfo.c
-
- g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH,
- writable && parent_info->has_trash_dir);
-
- => We're NOT interested in whether the specified folder can be trashed, but whether it supports thrashing its child elements! (Only support, not actual write access!)
- This renders G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH useless for this purpose. */
bgstack15