Fix and simplify implementation of "IF EXIST":
- Don't make any difference between wildcard search and normal search
- This fixes handling DOS devices search (ie, IF EXIST C:\ReactOS\NUL now works)
- This fixes handling pagefile.sys without requiring specifing rights
- Also fix handling directory search, terminated with a \

CORE-11784

svn path=/trunk/; revision=74444
This commit is contained in:
Pierre Schweitzer 2017-05-01 21:14:38 +00:00
parent 3e2f6b9d2c
commit dd512f56a9

View file

@ -114,23 +114,36 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
}
else if (Cmd->If.Operator == IF_EXIST)
{
BOOL IsDir;
INT Size;
WIN32_FIND_DATA f;
HANDLE hFind;
/* IF EXIST filename: check if file exists (wildcards allowed) */
StripQuotes(Right);
if (_tcschr(Right, _T('*')) || _tcschr(Right, _T('?')))
Size = _tcslen(Right);
IsDir = (Right[Size - 1] == '\\');
if (IsDir)
Right[Size - 1] = 0;
hFind = FindFirstFile(Right, &f);
if (hFind != INVALID_HANDLE_VALUE)
{
WIN32_FIND_DATA f;
HANDLE hFind = FindFirstFile(Right, &f);
if (hFind != INVALID_HANDLE_VALUE)
if (IsDir)
{
result = ((f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
}
else
{
result = TRUE;
FindClose(hFind);
}
FindClose(hFind);
}
else
{
result = (GetFileAttributes(Right) != INVALID_FILE_ATTRIBUTES);
}
if (IsDir)
Right[Size - 1] = '\\';
}
else
{