[CMD] Fix 'if' command for root directories (#2394)

CORE-14797
This commit is contained in:
Katayama Hirofumi MZ 2020-02-27 23:12:20 +09:00 committed by GitHub
parent 2b067d6494
commit 4e263367f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -118,6 +118,7 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
INT Size;
WIN32_FIND_DATA f;
HANDLE hFind;
DWORD attrs;
/* IF EXIST filename: check if file exists (wildcards allowed) */
StripQuotes(Right);
@ -127,20 +128,24 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
if (IsDir)
Right[Size - 1] = 0;
hFind = FindFirstFile(Right, &f);
if (hFind != INVALID_HANDLE_VALUE)
{
if (IsDir)
{
result = ((f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
}
else
{
result = TRUE;
}
attrs = f.dwFileAttributes;
FindClose(hFind);
}
else
{
/* FindFirstFile fails at the root directory. */
attrs = GetFileAttributes(Right);
}
if (attrs == 0xFFFFFFFF)
result = FALSE;
else if (IsDir)
result = ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
else
result = TRUE;
if (IsDir)
Right[Size - 1] = '\\';