Module: wine Branch: master Commit: 5e2f9996baedbe389df93255a4dd1188cbdb6c56 URL: https://gitlab.winehq.org/wine/wine/-/commit/5e2f9996baedbe389df93255a4dd118... Author: Maarten De Braekeleer <maarten.debraekeleer(a)gmail.com> Date: Sat Jun 24 20:02:53 2023 +0200 cmd: Fix 'if exist' with a directory/ as a parameter. 'if exists' takes a parameter which can be directory, directory/, directory/. directory\ or directory\. for example, and should equate to true if the directory exists. The syntax directory\ is explicitly rejected by FindFirstFile and hence was not working - look for this specific case, and if found append a '.'. Follow-up commit of bc9d68bcbee5c9d4f4582f766a4f552870385361 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55130#add_comment --- programs/cmd/builtins.c | 4 ++-- programs/cmd/tests/test_builtins.cmd | 19 +++++++++++++++++-- programs/cmd/tests/test_builtins.cmd.exp | 5 ++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 3b2a192c828..badf41c17f6 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -2844,8 +2844,8 @@ int evaluate_if_condition(WCHAR *p, WCHAR **command, int *test, int *negate) int len = lstrlenW(param); if (!len) goto syntax_err; - /* FindFirstFile does not like a directory path ending in '\', append a '.' */ - if (param[len-1] == '\\') lstrcatW(param, L"."); + /* FindFirstFile does not like a directory path ending in '\' or '/', append a '.' */ + if (param[len-1] == '\\' || param[len-1] == '/') lstrcatW(param, L"."); hff = FindFirstFileW(param, &fd); *test = (hff != INVALID_HANDLE_VALUE ); diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index fe7bedb1362..eaee2900bc9 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -1138,9 +1138,9 @@ if exist subdir ( echo ERROR exist subdir not working ) if exist subdir\. ( - echo exist subdir with . ok + echo exist subdir with \. ok ) else ( - echo ERROR exist subdir with . not working + echo ERROR exist subdir with \. not working ) if exist subdir\ ( echo exist subdir with \ ok @@ -1152,6 +1152,21 @@ if exist "subdir\" ( ) else ( echo ERROR exist subdir with \ and quotes not working ) +if exist subdir/. ( + echo exist subdir with /. ok +) else ( + echo ERROR exist subdir with /. not working +) +if exist subdir/ ( + echo exist subdir with / ok +) else ( + echo ERROR exist subdir with / not working +) +if exist "subdir/" ( + echo exist subdir with / and quotes ok +) else ( + echo ERROR exist subdir with / and quotes not working +) del foo subdir\bar rd subdir diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index 91570a7990f..411eae303ac 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -821,9 +821,12 @@ exist wildcard works negate exist wildcard works exist wildcard bad subdir broken works exist subdir ok -exist subdir with . ok +exist subdir with \. ok exist subdir with \ ok exist subdir with \ and quotes ok +exist subdir with /. ok +exist subdir with / ok +exist subdir with / and quotes ok ------ for numbers negative numbers handled negative numbers handled