Skip to content
Snippets Groups Projects
Commit bc9d68bc authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard
Browse files

cmd: Fix 'if exist' with a directory\ as a parameter.

'if exists' takes a parameter which can be 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 '.'.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45506


Signed-off-by: default avatarJason Edmeades <us@edmeades.me.uk>
Signed-off-by: Alexandre Julliard's avatarAlexandre Julliard <julliard@winehq.org>
parent 8b6ba774
No related branches found
No related tags found
No related merge requests found
......@@ -2861,7 +2861,14 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList)
}
else if (!lstrcmpiW (condition, existW)) {
WIN32_FIND_DATAW fd;
HANDLE hff = FindFirstFileW(WCMD_parameter(p, 1+negate, NULL, FALSE, FALSE), &fd);
HANDLE hff;
WCHAR *param = WCMD_parameter(p, 1+negate, NULL, FALSE, FALSE);
int len = strlenW(param);
/* FindFirstFile does not like a directory path ending in '\', append a '.' */
if (len && param[len-1] == '\\') strcatW(param, dotW);
hff = FindFirstFileW(param, &fd);
test = (hff != INVALID_HANDLE_VALUE );
if (test) FindClose(hff);
......
......@@ -1046,6 +1046,26 @@ if exist idontexist\ba* (
) else (
echo exist wildcard bad subdir broken works
)
if exist subdir (
echo exist subdir ok
) else (
echo ERROR exist subdir 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
......
......@@ -783,6 +783,10 @@ exist simple wildcard works
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 \ and quotes ok
------ for numbers
negative numbers handled
negative numbers handled
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment