Patch to fix bug 34324

Zhenbo Li litimetal at gmail.com
Wed Feb 19 03:47:45 CST 2014


Hello,
I've been working on http://bugs.winehq.org/show_bug.cgi?id=34324.
Till now, I have found two solutions, one is simple and one is
complex. Both of them would fix #34324, and I don't know which one is
better.

As Alexandre Julliard mentioned[1], I would use the value of
GetLastError() as the return (error) value in delete_files().

The simple patch would fix part of the 'todo_wine' marks.
Meanwhile, the complex patch would fix *all* todo marks about return
value in test_delete().

I really appreciate your help (especially for Dmitry Timoshkov, thank
you very much). And I'm looking for your feedbacks.

Thank you.

[1]: http://markmail.org/message/fblet7gadeusyauv#query:+page:1+mid:6eu2a72uuchhmsfz+state:results
-- 
Have a nice day!
Zhenbo Li
-------------- next part --------------
diff --git a/dlls/shell32/shlfileop.c b/dlls/shell32/shlfileop.c
index 4ef7803..07c76de 100644
--- a/dlls/shell32/shlfileop.c
+++ b/dlls/shell32/shlfileop.c
@@ -352,10 +352,16 @@ static BOOL SHELL_DeleteDirectoryW(HWND hwnd, LPCWSTR pszDir, BOOL bShowUI)
 	WCHAR   szTemp[MAX_PATH];
 
 	/* Make sure the directory exists before eventually prompting the user */
-	PathCombineW(szTemp, pszDir, wWildcardFile);
+	hFind = FindFirstFileW(pszDir, &wfd);
+	if (hFind == INVALID_HANDLE_VALUE){
+      if (GetLastError() == ERROR_PATH_NOT_FOUND)
+       SetLastError(0x7c);  /* DE_INVALIDFILES */
+    	return FALSE;
+    }
+    FindClose(hFind);
+
+    PathCombineW(szTemp, pszDir, wWildcardFile);
 	hFind = FindFirstFileW(szTemp, &wfd);
-	if (hFind == INVALID_HANDLE_VALUE)
-	  return FALSE;
 
 	if (!bShowUI || (ret = SHELL_ConfirmDialogW(hwnd, ASK_DELETE_FOLDER, pszDir, NULL)))
 	{
@@ -1380,7 +1386,7 @@ static DWORD delete_files(LPSHFILEOPSTRUCTW lpFileOp, const FILE_LIST *flFrom)
             bPathExists = SHELL_DeleteDirectoryW(lpFileOp->hwnd, fileEntry->szFullPath, FALSE);
 
         if (!bPathExists)
-            return ERROR_PATH_NOT_FOUND;
+            return GetLastError();
     }
 
     return ERROR_SUCCESS;
diff --git a/dlls/shell32/tests/shlfileop.c b/dlls/shell32/tests/shlfileop.c
index 14ace24..d02e3f2 100644
--- a/dlls/shell32/tests/shlfileop.c
+++ b/dlls/shell32/tests/shlfileop.c
@@ -622,7 +622,6 @@ static void test_delete(void)
     shfo.pFrom = "nonexistent.txt\0";
     shfo.wFunc = FO_DELETE;
     ret = SHFileOperationA(&shfo);
-    todo_wine
     ok(ret == 1026 ||
        ret == ERROR_FILE_NOT_FOUND || /* Vista */
        broken(ret == ERROR_SUCCESS), /* NT4 */
@@ -651,7 +650,6 @@ static void test_delete(void)
     shfo.pFrom = "test1.txt\0nonexistent.txt\0test2.txt\0";
     shfo.wFunc = FO_DELETE;
     ret = SHFileOperationA(&shfo);
-    todo_wine
     ok(ret == 1026 ||
        ret == ERROR_FILE_NOT_FOUND || /* Vista */
        broken(ret == ERROR_SUCCESS), /* NT4 */
@@ -664,14 +662,12 @@ static void test_delete(void)
     init_shfo_tests();
     shfo.pFrom = "testdir2\\nonexistent.txt\0";
     ret = SHFileOperationA(&shfo);
-    todo_wine
     ok(ret == ERROR_FILE_NOT_FOUND || /* Vista */
        broken(ret == 0x402) || /* XP */
        broken(ret == ERROR_SUCCESS), /* NT4 */
        "Expected 0x402 or ERROR_FILE_NOT_FOUND, got %x\n", ret);
     shfo.pFrom = "nonexistent\\one.txt\0";
     ret = SHFileOperationA(&shfo);
-    todo_wine
     ok(ret == DE_INVALIDFILES || /* Vista or later */
        broken(ret == 0x402), /* XP */
        "Expected 0x402 or DE_INVALIDFILES, got %x\n", ret);
-------------- next part --------------
diff --git a/dlls/shell32/shlfileop.c b/dlls/shell32/shlfileop.c
index 4ef7803..0eab9af 100644
--- a/dlls/shell32/shlfileop.c
+++ b/dlls/shell32/shlfileop.c
@@ -354,8 +354,10 @@ static BOOL SHELL_DeleteDirectoryW(HWND hwnd, LPCWSTR pszDir, BOOL bShowUI)
 	/* Make sure the directory exists before eventually prompting the user */
 	PathCombineW(szTemp, pszDir, wWildcardFile);
 	hFind = FindFirstFileW(szTemp, &wfd);
-	if (hFind == INVALID_HANDLE_VALUE)
+	if (hFind == INVALID_HANDLE_VALUE){
+     SetLastError(ERROR_FILE_NOT_FOUND);
 	  return FALSE;
+    }
 
 	if (!bShowUI || (ret = SHELL_ConfirmDialogW(hwnd, ASK_DELETE_FOLDER, pszDir, NULL)))
 	{
@@ -1380,7 +1382,7 @@ static DWORD delete_files(LPSHFILEOPSTRUCTW lpFileOp, const FILE_LIST *flFrom)
             bPathExists = SHELL_DeleteDirectoryW(lpFileOp->hwnd, fileEntry->szFullPath, FALSE);
 
         if (!bPathExists)
-            return ERROR_PATH_NOT_FOUND;
+            return GetLastError();
     }
 
     return ERROR_SUCCESS;
diff --git a/dlls/shell32/tests/shlfileop.c b/dlls/shell32/tests/shlfileop.c
index 14ace24..f161d01 100644
--- a/dlls/shell32/tests/shlfileop.c
+++ b/dlls/shell32/tests/shlfileop.c
@@ -622,7 +622,6 @@ static void test_delete(void)
     shfo.pFrom = "nonexistent.txt\0";
     shfo.wFunc = FO_DELETE;
     ret = SHFileOperationA(&shfo);
-    todo_wine
     ok(ret == 1026 ||
        ret == ERROR_FILE_NOT_FOUND || /* Vista */
        broken(ret == ERROR_SUCCESS), /* NT4 */
@@ -651,7 +650,6 @@ static void test_delete(void)
     shfo.pFrom = "test1.txt\0nonexistent.txt\0test2.txt\0";
     shfo.wFunc = FO_DELETE;
     ret = SHFileOperationA(&shfo);
-    todo_wine
     ok(ret == 1026 ||
        ret == ERROR_FILE_NOT_FOUND || /* Vista */
        broken(ret == ERROR_SUCCESS), /* NT4 */
@@ -664,7 +662,6 @@ static void test_delete(void)
     init_shfo_tests();
     shfo.pFrom = "testdir2\\nonexistent.txt\0";
     ret = SHFileOperationA(&shfo);
-    todo_wine
     ok(ret == ERROR_FILE_NOT_FOUND || /* Vista */
        broken(ret == 0x402) || /* XP */
        broken(ret == ERROR_SUCCESS), /* NT4 */


More information about the wine-devel mailing list