[PATCH v2 0/2] MR11094: cmd: Add wildcard expansion for type command.
Fixes: https://bugs.winehq.org/show_bug.cgi?id=59816 Signed-off-by: Barath Kannan barathrk11@gmail.com -- v2: cmd: Implement wildcard expansion for the type command's arguments. cmd: Add tests for type wildcard expansion. https://gitlab.winehq.org/wine/wine/-/merge_requests/11094
From: Barath Kannan <barathrk11@gmail.com> Signed-off-by: Barath Kannan <barathrk11@gmail.com> --- programs/cmd/tests/test_builtins.bat | 9 +++++++-- programs/cmd/tests/test_builtins.bat.exp | 14 ++++++++++---- programs/cmd/tests/test_builtins.cmd | 9 +++++++-- programs/cmd/tests/test_builtins.cmd.exp | 14 ++++++++++---- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/programs/cmd/tests/test_builtins.bat b/programs/cmd/tests/test_builtins.bat index 4c3d0e7107e..7e8f08c20e3 100644 --- a/programs/cmd/tests/test_builtins.bat +++ b/programs/cmd/tests/test_builtins.bat @@ -107,8 +107,13 @@ call :setError 666 & (type i\dont\exist\at\all.txt &&echo SUCCESS !errorlevel!|| call :setError 666 & (type file* i\dont\exist\at\all.txt &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!) echo --- call :setError 666 & (type i\dont\exist\at\all.txt file* &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!) -cd .. && rd /q /s foo - +mkdir bar +mkdir spam +cd .. +call :setError 666 & (type foo\file* &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!) +del foo\file* +call :setError 666 & (type foo\* &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!) +rd /q /s foo echo --- success/failure for COPY command mkdir foo & cd foo echo a > fileA diff --git a/programs/cmd/tests/test_builtins.bat.exp b/programs/cmd/tests/test_builtins.bat.exp index 36e14d5be91..6c4f86bc32e 100644 --- a/programs/cmd/tests/test_builtins.bat.exp +++ b/programs/cmd/tests/test_builtins.bat.exp @@ -67,11 +67,17 @@ SUCCESS 1024 FAILURE 1 SUCCESS 0 FAILURE 1 -@todo_wine@a@space@ -@todo_wine@b@space@ -@todo_wine@FAILURE 1 -@todo_wine@--- +a@space@ +b@space@ FAILURE 1 +--- +a@space@ +b@space@ +SUCCESS 0 +a@space@ +b@space@ +SUCCESS 0 +FAILURE 3 --- success/failure for COPY command FAILURE 1 SUCCESS 0 diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index f65a301d914..1921f6d91c5 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -690,8 +690,13 @@ call :setError 666 & (type i\dont\exist\at\all.txt &&echo SUCCESS !errorlevel!|| call :setError 666 & (type file* i\dont\exist\at\all.txt &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!) echo --- call :setError 666 & (type i\dont\exist\at\all.txt file* &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!) -cd .. && rd /q /s foo - +mkdir bar +mkdir spam +cd .. +call :setError 666 & (type foo\file* &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!) +del foo\file* +call :setError 666 & (type foo\* &&echo SUCCESS !errorlevel!||echo FAILURE !errorlevel!) +rd /q /s foo echo --- success/failure for COPY command mkdir foo & cd foo echo a > fileA diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index 0f6d9bdb494..e48a029084c 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -586,11 +586,17 @@ SUCCESS 1024 FAILURE 1 SUCCESS 0 FAILURE 1 -@todo_wine@a@space@ -@todo_wine@b@space@ -@todo_wine@FAILURE 1 -@todo_wine@--- +a@space@ +b@space@ FAILURE 1 +--- +a@space@ +b@space@ +SUCCESS 0 +a@space@ +b@space@ +SUCCESS 0 +FAILURE 3 --- success/failure for COPY command FAILURE 1 SUCCESS 0 -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11094
From: Barath Kannan <barathrk11@gmail.com> Signed-off-by: Barath Kannan <barathrk11@gmail.com> --- programs/cmd/builtins.c | 90 +++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 12 deletions(-) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 1c9074b75d3..1f96ce09543 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -30,6 +30,7 @@ #include "wcmd.h" #include <shellapi.h> +#include "shlwapi.h" #include "winternl.h" #include "winioctl.h" #include "ddk/ntifs.h" @@ -2365,7 +2366,7 @@ RETURN_CODE WCMD_setshow_default(const WCHAR *args) WCHAR ext[MAX_PATH]; /* Convert path into actual directory spec */ - if (!WCMD_get_fullpath(string, ARRAY_SIZE(fpath), fpath, NULL)) + if (!WCMD_get_fullpath(string, ARRAY_SIZE(fpath), fpath, NULL)) return errorlevel = ERROR_INVALID_FUNCTION; _wsplitpath(fpath, drive, dir, fname, ext); @@ -3439,6 +3440,11 @@ RETURN_CODE WCMD_type(WCHAR *args) int argno = 0; WCHAR *argN = args; BOOL writeHeaders = FALSE; + BOOL foundOnlyDirectories = TRUE; + WIN32_FIND_DATAW fd; + HANDLE hff = INVALID_HANDLE_VALUE; + WCHAR *fileNamePart; + WCHAR srcpath[MAX_PATH]; if (param1[0] == 0x00) { WCMD_output_stderr(WCMD_LoadMessage(WCMD_NOARG)); @@ -3454,26 +3460,86 @@ RETURN_CODE WCMD_type(WCHAR *args) HANDLE hIn, hOut; DWORD console_mode; + DWORD arg_len; + DWORD file_name_part_len; if (!argN) break; - WINE_TRACE("type: Processing arg '%s'\n", wine_dbgstr_w(thisArg)); - hIn = CreateFileW(thisArg, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, NULL); - if (hIn == INVALID_HANDLE_VALUE) { + arg_len = wcslen(thisArg); + + if (arg_len > MAX_PATH) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + WCMD_print_error (); + WCMD_output_stderr(WCMD_LoadMessage(WCMD_READFAIL), thisArg); + return errorlevel = ERROR_FILENAME_EXCED_RANGE; + } + + lstrcpyW(srcpath, thisArg); + + writeHeaders = writeHeaders || (wcspbrk(srcpath, L"*?") ? TRUE : FALSE); + + fileNamePart = PathFindFileNameW(srcpath); + + hff = FindFirstFileW(srcpath, &fd); + + if (hff != INVALID_HANDLE_VALUE) { + do { + file_name_part_len = wcslen(fd.cFileName); + + if ((arg_len + file_name_part_len) > MAX_PATH) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + WCMD_print_error (); + WCMD_output_stderr(WCMD_LoadMessage(WCMD_READFAIL), thisArg); + FindClose(hff); + return errorlevel = ERROR_FILENAME_EXCED_RANGE; + } + + lstrcpyW(fileNamePart, fd.cFileName); + + WINE_TRACE("type: thisArg: '%s'\n", wine_dbgstr_w(srcpath)); + + hIn = CreateFileW(srcpath, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); + if (hIn == INVALID_HANDLE_VALUE) { + if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + WINE_TRACE("Skipping directories\n"); + continue; + } + + WCMD_print_error (); + WCMD_output_stderr(WCMD_LoadMessage(WCMD_READFAIL), thisArg); + FindClose(hff); + return errorlevel = ERROR_INVALID_FUNCTION; + } + + foundOnlyDirectories = FALSE; + hOut = GetStdHandle(STD_OUTPUT_HANDLE); + + if (writeHeaders) { + WCMD_output_stderr(L"\n%1\n\n\n", srcpath); + } + + WCMD_copy_loop(hIn, hOut, GetConsoleMode(hIn, &console_mode) || GetConsoleMode(hOut, &console_mode)); + + return_code = NO_ERROR; + CloseHandle (hIn); + } while (FindNextFileW(hff, &fd) != 0); + } + else { + foundOnlyDirectories = FALSE; + return_code = ERROR_INVALID_FUNCTION; WCMD_print_error (); WCMD_output_stderr(WCMD_LoadMessage(WCMD_READFAIL), thisArg); - return errorlevel = ERROR_INVALID_FUNCTION; } - hOut = GetStdHandle(STD_OUTPUT_HANDLE); - if (writeHeaders) { - WCMD_output_stderr(L"\n%1\n\n\n", thisArg); + if (foundOnlyDirectories) { + return_code = ERROR_PATH_NOT_FOUND; + WCMD_print_error (); + WCMD_output_stderr(WCMD_LoadMessage(WCMD_READFAIL), thisArg); } - WCMD_copy_loop(hIn, hOut, GetConsoleMode(hIn, &console_mode) || GetConsoleMode(hOut, &console_mode)); - - CloseHandle (hIn); + foundOnlyDirectories = TRUE; + FindClose (hff); } return errorlevel = return_code; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11094
On Wed Jun 10 17:47:44 2026 +0000, eric pouech wrote:
* please don't open new merge requests; you can just update the first MR with the relevant changes * additional tests should come as first commit in MR so that one can easily review what has been changed (and tests from first MR shall not generate errors, so mark failing tests with @todo_wine@) tests are now in the first commit.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/11094#note_142670
On Wed Jun 10 17:44:29 2026 +0000, Barath Kannan wrote:
changed this line in [version 2 of the diff](/wine/wine/-/merge_requests/11094/diffs?diff_id=274117&start_sha=b4d9df4ec33eca0f9fe3346e221d78f182ef92d1#5da6ff77f01131f15f0584e3da4bfbcdb6790735_3479_3504) fixed this and added a test to ensure that an error(ERROR_PATH_NOT_FOUND) is thrown.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/11094#note_142671
participants (2)
-
Barath Kannan -
Barath Kannan (@barath_kannan)