https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4e263367f861f58173643e...
commit 4e263367f861f58173643eb511f8db88f7c6dd6b Author: Katayama Hirofumi MZ katayama.hirofumi.mz@gmail.com AuthorDate: Thu Feb 27 23:12:20 2020 +0900 Commit: GitHub noreply@github.com CommitDate: Thu Feb 27 23:12:19 2020 +0900
[CMD] Fix 'if' command for root directories (#2394)
CORE-14797 --- base/shell/cmd/if.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/base/shell/cmd/if.c b/base/shell/cmd/if.c index 8f9c5e71b00..c1e7e194efa 100644 --- a/base/shell/cmd/if.c +++ b/base/shell/cmd/if.c @@ -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] = '\';