shell32: Fix SHFileOperation when deleting a nonexistent directory.
This commit is contained in:
parent
d0803ef1d0
commit
2ba9ee018b
@ -347,36 +347,36 @@ HRESULT WINAPI SHIsFileAvailableOffline(LPCWSTR path, LPDWORD status)
|
|||||||
* Asks for confirmation when bShowUI is true and deletes the directory and
|
* Asks for confirmation when bShowUI is true and deletes the directory and
|
||||||
* all its subdirectories and files if necessary.
|
* all its subdirectories and files if necessary.
|
||||||
*/
|
*/
|
||||||
static BOOL SHELL_DeleteDirectoryW(HWND hwnd, LPCWSTR pszDir, BOOL bShowUI)
|
static DWORD SHELL_DeleteDirectoryW(HWND hwnd, LPCWSTR pszDir, BOOL bShowUI)
|
||||||
{
|
{
|
||||||
BOOL ret = TRUE;
|
DWORD ret = 0;
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
WIN32_FIND_DATAW wfd;
|
WIN32_FIND_DATAW wfd;
|
||||||
WCHAR szTemp[MAX_PATH];
|
WCHAR szTemp[MAX_PATH];
|
||||||
|
|
||||||
/* Make sure the directory exists before eventually prompting the user */
|
PathCombineW(szTemp, pszDir, wWildcardFile);
|
||||||
PathCombineW(szTemp, pszDir, wWildcardFile);
|
hFind = FindFirstFileW(szTemp, &wfd);
|
||||||
hFind = FindFirstFileW(szTemp, &wfd);
|
|
||||||
if (hFind == INVALID_HANDLE_VALUE)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (!bShowUI || (ret = SHELL_ConfirmDialogW(hwnd, ASK_DELETE_FOLDER, pszDir, NULL)))
|
if (hFind != INVALID_HANDLE_VALUE) {
|
||||||
{
|
if (!bShowUI || SHELL_ConfirmDialogW(hwnd, ASK_DELETE_FOLDER, pszDir, NULL)) {
|
||||||
do
|
do {
|
||||||
{
|
if (IsDotDir(wfd.cFileName))
|
||||||
if (IsDotDir(wfd.cFileName))
|
continue;
|
||||||
continue;
|
PathCombineW(szTemp, pszDir, wfd.cFileName);
|
||||||
PathCombineW(szTemp, pszDir, wfd.cFileName);
|
if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
|
||||||
if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
|
ret = SHELL_DeleteDirectoryW(hwnd, szTemp, FALSE);
|
||||||
ret = SHELL_DeleteDirectoryW(hwnd, szTemp, FALSE);
|
else
|
||||||
else
|
ret = SHNotifyDeleteFileW(szTemp);
|
||||||
ret = (SHNotifyDeleteFileW(szTemp) == ERROR_SUCCESS);
|
} while (!ret && FindNextFileW(hFind, &wfd));
|
||||||
} while (ret && FindNextFileW(hFind, &wfd));
|
}
|
||||||
}
|
FindClose(hFind);
|
||||||
FindClose(hFind);
|
}
|
||||||
if (ret)
|
if (ret == ERROR_SUCCESS)
|
||||||
ret = (SHNotifyRemoveDirectoryW(pszDir) == ERROR_SUCCESS);
|
ret = SHNotifyRemoveDirectoryW(pszDir);
|
||||||
return ret;
|
|
||||||
|
return ret == ERROR_PATH_NOT_FOUND ?
|
||||||
|
0x7C: /* DE_INVALIDFILES (legacy Windows error) */
|
||||||
|
ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
@ -1331,8 +1331,7 @@ static BOOL confirm_delete_list(HWND hWnd, DWORD fFlags, BOOL fTrash, const FILE
|
|||||||
static DWORD delete_files(LPSHFILEOPSTRUCTW lpFileOp, const FILE_LIST *flFrom)
|
static DWORD delete_files(LPSHFILEOPSTRUCTW lpFileOp, const FILE_LIST *flFrom)
|
||||||
{
|
{
|
||||||
const FILE_ENTRY *fileEntry;
|
const FILE_ENTRY *fileEntry;
|
||||||
DWORD i;
|
DWORD i, ret;
|
||||||
BOOL bPathExists;
|
|
||||||
BOOL bTrash;
|
BOOL bTrash;
|
||||||
|
|
||||||
if (!flFrom->dwNumFiles)
|
if (!flFrom->dwNumFiles)
|
||||||
@ -1378,12 +1377,13 @@ static DWORD delete_files(LPSHFILEOPSTRUCTW lpFileOp, const FILE_LIST *flFrom)
|
|||||||
|
|
||||||
/* delete the file or directory */
|
/* delete the file or directory */
|
||||||
if (IsAttribFile(fileEntry->attributes))
|
if (IsAttribFile(fileEntry->attributes))
|
||||||
bPathExists = DeleteFileW(fileEntry->szFullPath);
|
ret = DeleteFileW(fileEntry->szFullPath) ?
|
||||||
|
ERROR_SUCCESS : GetLastError();
|
||||||
else
|
else
|
||||||
bPathExists = SHELL_DeleteDirectoryW(lpFileOp->hwnd, fileEntry->szFullPath, FALSE);
|
ret = SHELL_DeleteDirectoryW(lpFileOp->hwnd, fileEntry->szFullPath, FALSE);
|
||||||
|
|
||||||
if (!bPathExists)
|
if (ret)
|
||||||
return ERROR_PATH_NOT_FOUND;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
|
@ -622,7 +622,6 @@ static void test_delete(void)
|
|||||||
shfo.pFrom = "nonexistent.txt\0";
|
shfo.pFrom = "nonexistent.txt\0";
|
||||||
shfo.wFunc = FO_DELETE;
|
shfo.wFunc = FO_DELETE;
|
||||||
ret = SHFileOperationA(&shfo);
|
ret = SHFileOperationA(&shfo);
|
||||||
todo_wine
|
|
||||||
ok(ret == 1026 ||
|
ok(ret == 1026 ||
|
||||||
ret == ERROR_FILE_NOT_FOUND || /* Vista */
|
ret == ERROR_FILE_NOT_FOUND || /* Vista */
|
||||||
broken(ret == ERROR_SUCCESS), /* NT4 */
|
broken(ret == ERROR_SUCCESS), /* NT4 */
|
||||||
@ -651,7 +650,6 @@ static void test_delete(void)
|
|||||||
shfo.pFrom = "test1.txt\0nonexistent.txt\0test2.txt\0";
|
shfo.pFrom = "test1.txt\0nonexistent.txt\0test2.txt\0";
|
||||||
shfo.wFunc = FO_DELETE;
|
shfo.wFunc = FO_DELETE;
|
||||||
ret = SHFileOperationA(&shfo);
|
ret = SHFileOperationA(&shfo);
|
||||||
todo_wine
|
|
||||||
ok(ret == 1026 ||
|
ok(ret == 1026 ||
|
||||||
ret == ERROR_FILE_NOT_FOUND || /* Vista */
|
ret == ERROR_FILE_NOT_FOUND || /* Vista */
|
||||||
broken(ret == ERROR_SUCCESS), /* NT4 */
|
broken(ret == ERROR_SUCCESS), /* NT4 */
|
||||||
@ -664,14 +662,12 @@ static void test_delete(void)
|
|||||||
init_shfo_tests();
|
init_shfo_tests();
|
||||||
shfo.pFrom = "testdir2\\nonexistent.txt\0";
|
shfo.pFrom = "testdir2\\nonexistent.txt\0";
|
||||||
ret = SHFileOperationA(&shfo);
|
ret = SHFileOperationA(&shfo);
|
||||||
todo_wine
|
|
||||||
ok(ret == ERROR_FILE_NOT_FOUND || /* Vista */
|
ok(ret == ERROR_FILE_NOT_FOUND || /* Vista */
|
||||||
broken(ret == 0x402) || /* XP */
|
broken(ret == 0x402) || /* XP */
|
||||||
broken(ret == ERROR_SUCCESS), /* NT4 */
|
broken(ret == ERROR_SUCCESS), /* NT4 */
|
||||||
"Expected 0x402 or ERROR_FILE_NOT_FOUND, got %x\n", ret);
|
"Expected 0x402 or ERROR_FILE_NOT_FOUND, got %x\n", ret);
|
||||||
shfo.pFrom = "nonexistent\\one.txt\0";
|
shfo.pFrom = "nonexistent\\one.txt\0";
|
||||||
ret = SHFileOperationA(&shfo);
|
ret = SHFileOperationA(&shfo);
|
||||||
todo_wine
|
|
||||||
ok(ret == DE_INVALIDFILES || /* Vista or later */
|
ok(ret == DE_INVALIDFILES || /* Vista or later */
|
||||||
broken(ret == 0x402), /* XP */
|
broken(ret == 0x402), /* XP */
|
||||||
"Expected 0x402 or DE_INVALIDFILES, got %x\n", ret);
|
"Expected 0x402 or DE_INVALIDFILES, got %x\n", ret);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user