From: yaoyongjie yaoyongjie@uniontech.com
In CopyFileEx, and DeleteFile functions, by default, the file name and path are limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, need prepend "\\?\" to the path. --- dlls/kernel32/tests/file.c | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index 68b9f53700e..4b6fbbcf867 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -910,6 +910,12 @@ static void test_CopyFileW(void) WCHAR source[MAX_PATH], dest[MAX_PATH]; static const WCHAR prefix[] = {'p','f','x',0}; DWORD ret; + /* long file name, 247 charactors */ + const WCHAR *long_name_1 = L"a2345678lsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfie.txt"; + const WCHAR *long_name_2 = L"b2345678lsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfie.txt"; + /* long file path is %TEMP%/%long_name% */ + WCHAR long_path_1[MAX_PATH * 2] = { 0 }; + WCHAR long_path_2[MAX_PATH * 2] = { 0 };
ret = GetTempPathW(MAX_PATH, temp_path); if (ret == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) @@ -942,6 +948,40 @@ static void test_CopyFileW(void) ok(GetLastError() == ERROR_SUCCESS || broken(GetLastError() == ERROR_INVALID_PARAMETER) /* some win8 machines */, "Unexpected error %lu.\n", GetLastError());
+ /* test long file path, the length of the long_dest is larger than MAX_PATH. */ + wcscpy(long_path_1, temp_path); + wcscat(long_path_1, long_name_1); + SetLastError(0xdeadbeef); + ret = CopyFileExW(source, long_path_1, NULL, NULL, NULL, 0); + todo_wine ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND, "Expected CopyFileExW failed with ERROR_PATH_NOT_FOUND, but got %ld, copy %s -> %s\n", GetLastError(), wine_dbgstr_w(source), wine_dbgstr_w(long_path_1)); + wcscpy(long_path_2, temp_path); + wcscat(long_path_2, long_name_2); + SetLastError(0xdeadbeef); + ret = CopyFileExW(long_path_1, long_path_2, NULL, NULL, NULL, 0); + todo_wine ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND, "Expected CopyFileExW failed with ERROR_PATH_NOT_FOUND, but got %ld, copy %s -> %s\n", GetLastError(), wine_dbgstr_w(long_path_1), wine_dbgstr_w(long_path_2)); + ret = DeleteFileW(long_path_1); + todo_wine ok(!ret, "Unexpected DeleteFileW successed\n"); + ret = DeleteFileW(long_path_2); + todo_wine ok(!ret, "Unexpected DeleteFileW successed\n"); + + /* test long file name prepend "\?" */ + wcscpy(long_path_1, L"\\?\"); + wcscat(long_path_1, temp_path); + wcscat(long_path_1, long_name_1); + SetLastError(0xdeadbeef); + ret = CopyFileExW(source, long_path_1, NULL, NULL, NULL, 0); + ok(ret, "CopyFileExW failed, got %ld, copy %s -> %s failed\n", GetLastError(), wine_dbgstr_w(source), wine_dbgstr_w(long_path_1)); + wcscpy(long_path_2, L"\\?\"); + wcscat(long_path_2, temp_path); + wcscat(long_path_2, long_name_2); + SetLastError(0xdeadbeef); + ret = CopyFileExW(long_path_1, long_path_2, NULL, NULL, NULL, 0); + ok(ret, "CopyFileExW failed, got %ld, copy %s -> %s failed\n", GetLastError(), wine_dbgstr_w(long_path_1), wine_dbgstr_w(long_path_2)); + ret = DeleteFileW(long_path_1); + ok(ret, "DeleteFileW: error %ld\n", GetLastError()); + ret = DeleteFileW(long_path_2); + ok(ret, "DeleteFileW: error %ld\n", GetLastError()); + ret = DeleteFileW(source); ok(ret, "DeleteFileW: error %ld\n", GetLastError()); ret = DeleteFileW(dest); @@ -1194,6 +1234,12 @@ static void test_CopyFileEx(void) HANDLE hfile; DWORD ret; BOOL retok; + /* long file name, 247 charactors */ + const char *long_name_1 = "a2345678lsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfie.txt"; + const char *long_name_2 = "b2345678lsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfielfelfjellsfalfielsfleflsfie.txt"; + /* long file path is %TEMP%/%long_name% */ + char long_path_1[MAX_PATH * 2] = { 0 }; + char long_path_2[MAX_PATH * 2] = { 0 };
ret = GetTempPathA(MAX_PATH, temp_path); ok(ret != 0, "GetTempPathA error %ld\n", GetLastError()); @@ -1235,6 +1281,40 @@ static void test_CopyFileEx(void) ok(!retok, "CopyFileExA unexpectedly succeeded\n"); ok(GetLastError() == ERROR_PATH_NOT_FOUND, "expected ERROR_PATH_NOT_FOUND, got %ld\n", GetLastError());
+ /* test long file path, the length of the long_dest is larger than MAX_PATH. */ + strcpy(long_path_1, temp_path); + strcat(long_path_1, long_name_1); + SetLastError(0xdeadbeef); + retok = CopyFileExA(source, long_path_1, NULL, NULL, NULL, 0); + todo_wine ok(!retok && GetLastError() == ERROR_PATH_NOT_FOUND, "Expected CopyFileExA failed with ERROR_PATH_NOT_FOUND, but got %ld, copy %s -> %s\n", GetLastError(), source, long_path_1); + strcpy(long_path_2, temp_path); + strcat(long_path_2, long_name_2); + SetLastError(0xdeadbeef); + retok = CopyFileExA(long_path_1, long_path_2, NULL, NULL, NULL, 0); + todo_wine ok(!retok && GetLastError() == ERROR_PATH_NOT_FOUND, "Expected CopyFileExA failed with ERROR_PATH_NOT_FOUND, but got %ld, copy %s -> %s\n", GetLastError(), long_path_1, long_path_2); + retok = DeleteFileA(long_path_1); + todo_wine ok(!retok, "Unexpected DeleteFileA successed\n"); + retok = DeleteFileA(long_path_2); + todo_wine ok(!retok, "Unexpected DeleteFileA successed\n"); + + /* test long file name prepend "\?" */ + strcpy(long_path_1, "\\?\"); + strcat(long_path_1, temp_path); + strcat(long_path_1, long_name_1); + SetLastError(0xdeadbeef); + retok = CopyFileExA(source, long_path_1, NULL, NULL, NULL, 0); + ok(retok, "CopyFileExA failed, got %ld, copy %s -> %s failed\n", GetLastError(), source, long_path_1); + strcpy(long_path_2, "\\?\"); + strcat(long_path_2, temp_path); + strcat(long_path_2, long_name_2); + SetLastError(0xdeadbeef); + retok = CopyFileExA(long_path_1, long_path_2, NULL, NULL, NULL, 0); + ok(retok, "CopyFileExA failed, got %ld, copy %s -> %s failed\n", GetLastError(), long_path_1, long_path_2); + ret = DeleteFileA(long_path_1); + todo_wine ok(ret, "DeleteFileA failed with error %ld\n", GetLastError()); + ret = DeleteFileA(long_path_2); + todo_wine ok(ret, "DeleteFileA failed with error %ld\n", GetLastError()); + ret = DeleteFileA(source); ok(ret, "DeleteFileA failed with error %ld\n", GetLastError()); ret = DeleteFileA(dest);