diff options
Diffstat (limited to 'far2l')
-rwxr-xr-x | far2l/bootstrap/trash.sh | 12 | ||||
-rw-r--r-- | far2l/src/delete.cpp | 29 | ||||
-rw-r--r-- | far2l/src/message.cpp | 12 | ||||
-rw-r--r-- | far2l/src/message.hpp | 1 |
4 files changed, 43 insertions, 11 deletions
diff --git a/far2l/bootstrap/trash.sh b/far2l/bootstrap/trash.sh index 338bff5f..d185ef8a 100755 --- a/far2l/bootstrap/trash.sh +++ b/far2l/bootstrap/trash.sh @@ -12,8 +12,12 @@ if [ -x ~/.config/far2l/trash.sh ]; then . ~/.config/far2l/trash.sh fi -if command -v gvfs-trash >/dev/null 2>&1; then - gvfs-trash -f -- "$1" -elif command -v gio >/dev/null 2>&1; then - gio trash -f -- "$1" +if command -v gio >/dev/null 2>&1; then + gio trash -f -- "$1" 2>"$2" + +elif command -v gvfs-trash >/dev/null 2>&1; then + gvfs-trash -f -- "$1" 2>"$2" + +else + echo 'No gio or gvfs-trash available' >"$2" fi diff --git a/far2l/src/delete.cpp b/far2l/src/delete.cpp index 391e6731..4aacf5da 100644 --- a/far2l/src/delete.cpp +++ b/far2l/src/delete.cpp @@ -801,25 +801,40 @@ int ERemoveDirectory(const wchar_t *Name,int Wipe) return DELETE_SUCCESS; } -int RemoveToRecycleBin(const wchar_t *Name) +static int RemoveToRecycleBin(const wchar_t *Name) { - std::string name_mb = Wide2MB(Name); + FARString err_file; + FarMkTempEx(err_file, L"trash"); + + std::string name_arg = Wide2MB(Name); + std::string err_file_arg = err_file.GetMB(); unsigned int flags = EF_HIDEOUT; - if (sudo_client_is_required_for(name_mb.c_str(), true)) + if (sudo_client_is_required_for(name_arg.c_str(), true)) flags|= EF_SUDO; - QuoteCmdArgIfNeed(name_mb); + QuoteCmdArgIfNeed(name_arg); + QuoteCmdArgIfNeed(err_file_arg); std::string cmd = GetMyScriptQuoted("trash.sh"); cmd+= ' '; - cmd+= name_mb; + cmd+= name_arg; + cmd+= ' '; + cmd+= err_file_arg; int r = farExecuteA(cmd.c_str(), flags); - if (r==0) + if (r == 0) return TRUE; - errno = r; + std::string err_str; + if (ReadWholeFile(err_file.GetMB().c_str(), err_str, 0x10000)) { + // gio: file:///.../xxx/yyy: Unable to trash file .../xxx/yyy: Permission denied + err_str.erase(0, err_str.rfind(':') + 1); + StrTrim(err_str, " \t\r\n"); + SetErrorString(err_str); + } + unlink(err_file.GetMB().c_str()); + return FALSE; } diff --git a/far2l/src/message.cpp b/far2l/src/message.cpp index e2e273dc..3072e5d6 100644 --- a/far2l/src/message.cpp +++ b/far2l/src/message.cpp @@ -566,9 +566,16 @@ void GetMessagePosition(int &X1,int &Y1,int &X2,int &Y2) Y2=MessageY2; } +static FARString s_ErrorString; + bool GetErrorString(FARString &strErrStr) { auto err = errno; + if (err == -1 && !s_ErrorString.IsEmpty()) { + strErrStr = s_ErrorString; + return true; + } + const char *str = strerror(err); if (str) { strErrStr.Format(L"%s (%u)", str, err); @@ -578,6 +585,11 @@ bool GetErrorString(FARString &strErrStr) return true; } +void SetErrorString(const FARString &strErrStr) +{ + s_ErrorString = strErrStr; + errno = -1; +} void SetMessageHelp(const wchar_t *Topic) { diff --git a/far2l/src/message.hpp b/far2l/src/message.hpp index ee091471..ab5ba49e 100644 --- a/far2l/src/message.hpp +++ b/far2l/src/message.hpp @@ -93,3 +93,4 @@ void GetMessagePosition(int &X1,int &Y1,int &X2,int &Y2); int AbortMessage(); bool GetErrorString(FARString &strErrStr); +void SetErrorString(const FARString &strErrStr); |