shell: return status for moveItemToTrash on all platforms

This commit is contained in:
Robo 2015-03-27 18:31:57 +05:30
parent 8aae7c4440
commit bedea89dcf
5 changed files with 38 additions and 16 deletions

View file

@ -164,7 +164,7 @@ void OpenExternal(const GURL& url) {
}
}
void MoveItemToTrash(const base::FilePath& path) {
bool MoveItemToTrash(const base::FilePath& path) {
// SHFILEOPSTRUCT wants the path to be terminated with two NULLs,
// so we have to use wcscpy because wcscpy_s writes non-NULLs
// into the rest of the buffer.
@ -176,7 +176,20 @@ void MoveItemToTrash(const base::FilePath& path) {
file_operation.wFunc = FO_DELETE;
file_operation.pFrom = double_terminated_path;
file_operation.fFlags = FOF_ALLOWUNDO | FOF_SILENT | FOF_NOCONFIRMATION;
SHFileOperation(&file_operation);
int err = SHFileOperation(&file_operation);
// Since we're passing flags to the operation telling it to be silent,
// it's possible for the operation to be aborted/cancelled without err
// being set (although MSDN doesn't give any scenarios for how this can
// happen). See MSDN for SHFileOperation and SHFILEOPTSTRUCT.
if (file_operation.fAnyOperationsAborted)
return false;
// Some versions of Windows return ERROR_FILE_NOT_FOUND (0x2) when deleting
// an empty directory and some return 0x402 when they should be returning
// ERROR_FILE_NOT_FOUND. MSDN says Vista and up won't return 0x402. Windows 7
// can return DE_INVALIDFILES (0x7C) for nonexistent directories.
return (err == 0 || err == ERROR_FILE_NOT_FOUND || err == DE_INVALIDFILES);
}
void Beep() {