Fixes bug 45052
Add support for 'if exist filenam*' style statments with associated tests
Signed-off-by: Jason Edmeades us@edmeades.me.uk --- programs/cmd/builtins.c | 8 +++-- programs/cmd/tests/test_builtins.cmd | 43 ++++++++++++++++++++++++ programs/cmd/tests/test_builtins.cmd.exp | 8 +++++ 3 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 04b098e98d..541915df67 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -2804,8 +2804,12 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) WCMD_parameter(p, 2+negate, &command, FALSE, FALSE); } else if (!lstrcmpiW (condition, existW)) { - test = (GetFileAttributesW(WCMD_parameter(p, 1+negate, NULL, FALSE, FALSE)) - != INVALID_FILE_ATTRIBUTES); + HANDLE hff = INVALID_HANDLE_VALUE; + WIN32_FIND_DATAW fd; + hff = FindFirstFileW(WCMD_parameter(p, 1+negate, NULL, FALSE, FALSE), &fd); + test = (hff != INVALID_HANDLE_VALUE ); + if (!test) FindClose(hff); + WCMD_parameter(p, 2+negate, &command, FALSE, FALSE); } else if (!lstrcmpiW (condition, defdW)) { diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index 63ec3cacb1..d6edc5fff1 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -979,6 +979,49 @@ for %%i in (%WINE_STR_PARMS%) do ( for %%i in (%WINE_STR_PARMS%) do ( for %%j in (%WINE_STR_PARMS%) do ( call :GTRtest %%i %%j)) + +echo ------------ Testing if/exist ------------ +mkdir subdir +echo something>subdir\bar +echo something else>foo +if exist foo ( + echo exist explicit works +) else ( + echo ERROR exist explicit broken +) +if exist bar ( + echo ERROR exist explicit unknown file broken +) else ( + echo exist explicit unknown file works +) +if exist subdir\bar ( + echo exist explicit in subdir works +) else ( + echo ERROR exist explicit in subdir broken +) +if exist fo* ( + echo exist simple wildcard works +) else ( + echo ERROR exist simple wildcard broken +) +if exist subdir\ba* ( + echo exist wildcard works +) else ( + echo ERROR exist wildcard broken +) +if not exist subdir\ba* ( + echo ERROR negate exist wildcard broken +) else ( + echo negate exist wildcard works +) +if exist idontexist\ba* ( + echo ERROR exist wildcard bad subdir broken +) else ( + echo exist wildcard bad subdir broken works +) +del foo subdir\bar +rd subdir + echo ------ for numbers if -1 LSS 1 (echo negative numbers handled) if not -1 LSS -10 (echo negative numbers handled) diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index dcc96299b9..22d83c3b19 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -768,6 +768,14 @@ BA GTR B BA GTR AB BA GTR AA AA GTR A +------------ Testing if/exist ------------ +exist explicit works +exist explicit unknown file works +exist explicit in subdir works +exist simple wildcard works +exist wildcard works +negate exist wildcard works +exist wildcard bad subdir broken works ------ for numbers negative numbers handled negative numbers handled