From: Zhenbo Li Subject: [PATCH] shell32: Fix SHFileOperation(FO_MOVE) on non-exist files. Message-Id: <55EBB8F3.6030308@gmail.com> Date: Sun, 6 Sep 2015 11:54:27 +0800 The previous test for no outgoing files had chosen a non-exist file. If we're trying FO_MOVE on an existent file, and there is no destination, windows will return DE_SAMEFILE on Vista or later --- dlls/shell32/shlfileop.c | 5 ++++- dlls/shell32/tests/shlfileop.c | 17 +++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dlls/shell32/shlfileop.c b/dlls/shell32/shlfileop.c index c843dd7..be54941 100644 --- a/dlls/shell32/shlfileop.c +++ b/dlls/shell32/shlfileop.c @@ -1411,7 +1411,7 @@ static int move_files(LPSHFILEOPSTRUCTW lpFileOp, const FILE_LIST *flFrom, const return ERROR_SUCCESS; if (!flTo->dwNumFiles) - return ERROR_FILE_NOT_FOUND; + return DE_SAMEFILE; if (!(lpFileOp->fFlags & FOF_MULTIDESTFILES) && flTo->dwNumFiles > 1 && flFrom->dwNumFiles > 1) @@ -1440,6 +1440,9 @@ static int move_files(LPSHFILEOPSTRUCTW lpFileOp, const FILE_LIST *flFrom, const if (!PathFileExistsW(fileDest->szDirectory)) return ERROR_CANCELLED; + if (entryToMove->attributes == INVALID_FILE_ATTRIBUTES) + return ERROR_FILE_NOT_FOUND; + if (lpFileOp->fFlags & FOF_MULTIDESTFILES) { if (i >= flTo->dwNumFiles) diff --git a/dlls/shell32/tests/shlfileop.c b/dlls/shell32/tests/shlfileop.c index d33ad5b..40370de 100644 --- a/dlls/shell32/tests/shlfileop.c +++ b/dlls/shell32/tests/shlfileop.c @@ -2038,16 +2038,21 @@ static void test_move(void) init_shfo_tests(); /* 0 outgoing files */ - set_curr_dir_path(from, "test1\0\0"); + set_curr_dir_path(from, "test1.txt\0\0"); set_curr_dir_path(to, "\0\0"); retval = SHFileOperationA(&shfo2); - ok(retval == ERROR_FILE_NOT_FOUND || - broken(retval == 1026) - , "Expected ERROR_FILE_NOT_FOUND, got %d\n", retval); - ok(!file_exists("test6.txt"), "The file should not exist\n"); + ok(retval == DE_SAMEFILE || /* Vista, 2008, Win7, Win8 */ + broken(retval == ERROR_SUCCESS) /* 2000, XP, 2003 */ + , "Expected DE_SAMEFILE, got %08x\n", retval); - init_shfo_tests(); + set_curr_dir_path(from, "notexist\0"); + set_curr_dir_path(to, "testdir2\0"); + retval = SHFileOperationA(&shfo2); + ok(retval == ERROR_FILE_NOT_FOUND || /* Vista, 2008, Win7, Win8 */ + broken(retval == 0x402) /* 2000, XP, 2003 */ + , "Expected ERROR_FILE_NOT_FOUND, got %08x\n", retval); + init_shfo_tests(); set_curr_dir_path(from, "test3.txt\0"); set_curr_dir_path(to, "test4.txt\\test1.txt\0"); ok(!SHFileOperationA(&shfo), "Can't move file to other directory\n");