Skip to content

Commit

Permalink
Merge pull request ninja-build#2160 from zmodem/fix_FindFirstFileExA
Browse files Browse the repository at this point in the history
Handle ERROR_DIRECTORY when calling FindFirstFileExA
  • Loading branch information
nico authored Dec 9, 2022
2 parents 53346f1 + c47ff5a commit c6e002d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/disk_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ bool StatAllFilesInDir(const string& dir, map<string, TimeStamp>* stamps,

if (find_handle == INVALID_HANDLE_VALUE) {
DWORD win_err = GetLastError();
if (win_err == ERROR_FILE_NOT_FOUND || win_err == ERROR_PATH_NOT_FOUND)
if (win_err == ERROR_FILE_NOT_FOUND || win_err == ERROR_PATH_NOT_FOUND ||
win_err == ERROR_DIRECTORY)
return true;
*err = "FindFirstFileExA(" + dir + "): " + GetLastErrorString();
return false;
Expand Down
11 changes: 11 additions & 0 deletions src/disk_interface_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ TEST_F(DiskInterfaceTest, StatMissingFile) {
EXPECT_EQ("", err);
}

TEST_F(DiskInterfaceTest, StatMissingFileWithCache) {
disk_.AllowStatCache(true);
string err;

// On Windows, the errno for FindFirstFileExA, which is used when the stat
// cache is enabled, is different when the directory name is not a directory.
ASSERT_TRUE(Touch("notadir"));
EXPECT_EQ(0, disk_.Stat("notadir/nosuchfile", &err));
EXPECT_EQ("", err);
}

TEST_F(DiskInterfaceTest, StatBadPath) {
string err;
#ifdef _WIN32
Expand Down

0 comments on commit c6e002d

Please sign in to comment.