From 94db751716dd2851f99b5c4c2981da1d1f4780f8 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 2 Oct 2015 14:53:20 +0200 Subject: 6.11 --- zen/recycler.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'zen/recycler.cpp') diff --git a/zen/recycler.cpp b/zen/recycler.cpp index 930b05ac..5b5e44d4 100644 --- a/zen/recycler.cpp +++ b/zen/recycler.cpp @@ -5,12 +5,11 @@ // ************************************************************************** #include "recycler.h" -#include "file_handling.h" +#include "file_access.h" #ifdef ZEN_WIN #include "thread.h" #include "dll.h" -#include "assert_static.h" #include "win_ver.h" #include "long_path_prefix.h" #include "IFileOperation/file_op.h" @@ -46,11 +45,10 @@ Nevertheless, let's use IFileOperation for better error reporting (including det struct CallbackData { CallbackData(const std::function& notifyDeletionStatus) : - notifyDeletionStatus_(notifyDeletionStatus), - exceptionInUserCallback(false) {} + notifyDeletionStatus_(notifyDeletionStatus) {} - const std::function& notifyDeletionStatus_; //optional! - bool exceptionInUserCallback; + const std::function& notifyDeletionStatus_; //in, optional + std::exception_ptr exception; //out }; @@ -65,7 +63,7 @@ bool onRecyclerCallback(const wchar_t* itempath, void* sink) } catch (...) { - cbd.exceptionInUserCallback = true; //try again outside the C call stack! + cbd.exception = std::current_exception(); return false; } return true; @@ -85,8 +83,8 @@ void zen::recycleOrDelete(const std::vector& itempaths, const std::func if (vistaOrLater()) //new recycle bin usage: available since Vista { #define DEF_DLL_FUN(name) const DllFun name(fileop::getDllName(), fileop::funName_##name); -DEF_DLL_FUN(moveToRecycleBin); -DEF_DLL_FUN(getLastErrorMessage); + DEF_DLL_FUN(moveToRecycleBin); + DEF_DLL_FUN(getLastErrorMessage); #undef DEF_DLL_FUN if (!moveToRecycleBin || !getLastErrorMessage) @@ -100,12 +98,8 @@ DEF_DLL_FUN(getLastErrorMessage); CallbackData cbd(notifyDeletionStatus); if (!moveToRecycleBin(&cNames[0], cNames.size(), onRecyclerCallback, &cbd)) { - if (cbd.exceptionInUserCallback) - { - assert(notifyDeletionStatus); - notifyDeletionStatus(Zstring()); //should throw again!!! - assert(false); - } + if (cbd.exception) + std::rethrow_exception(cbd.exception); std::wstring itempathFmt = fmtFileName(itempaths[0]); //probably not the correct file name for file lists larger than 1! if (itempaths.size() > 1) @@ -188,7 +182,7 @@ bool zen::recycleOrDelete(const Zstring& itempath) //throw FileError #elif defined ZEN_MAC //we cannot use FSPathMoveObjectToTrashSync directly since it follows symlinks! - assert_static(sizeof(Zchar) == sizeof(char)); + static_assert(sizeof(Zchar) == sizeof(char), ""); const UInt8* itempathUtf8 = reinterpret_cast(itempath.c_str()); auto throwFileError = [&](OSStatus oss) -- cgit