Fix FileUtils::isDirectory not handling errors correctly on Win32

This commit is contained in:
vladmarica 2022-01-23 10:40:12 -08:00
parent d0a3173776
commit 41336505c6

View file

@ -190,7 +190,10 @@ bool traverseDirectory(const std::string& path, const std::function<void(const s
bool isDirectory(const std::string& path)
{
#ifdef _WIN32
return (GetFileAttributesW(fromUtf8(path).c_str()) & FILE_ATTRIBUTE_DIRECTORY) != 0;
DWORD fileAttributes = GetFileAttributesW(fromUtf8(path).c_str());
if (fileAttributes == INVALID_FILE_ATTRIBUTES)
return false;
return (fileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
#else
struct stat st = {};
lstat(path.c_str(), &st);
@ -244,8 +247,11 @@ std::vector<std::string> getSourceFiles(int argc, char** argv)
for (int i = 1; i < argc; ++i)
{
if (argv[i][0] == '-')
// Treat '-' as a special file whose source is read from stdin
// All other arguments that start with '-' are skipped
if (argv[i][0] == '-' && argv[i][1] != '\0') {
continue;
}
if (isDirectory(argv[i]))
{