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