diff options
author | Hans Wennborg <hans@chromium.org> | 2022-06-20 16:18:36 +0200 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2022-07-12 12:54:19 +0200 |
commit | c47ff5aa33d0928f20d06986f8331e3bb5eba3bc (patch) | |
tree | cdcec0173ef461ad11e17d267a8a8482634df281 | |
parent | d4017a2b1ea642f12dabe05ec99b2a16c93e99aa (diff) | |
download | ninja-c47ff5aa33d0928f20d06986f8331e3bb5eba3bc.tar.gz |
Handle ERROR_DIRECTORY when calling FindFirstFileExA
If a directory referenced by .ninja_deps has changed to a regular file
since the last build, FindFirstFileExA will return ERROR_DIRECTORY.
Fixes #2159
-rw-r--r-- | src/disk_interface.cc | 3 | ||||
-rw-r--r-- | src/disk_interface_test.cc | 11 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc index e73d901..fa716ed 100644 --- a/src/disk_interface.cc +++ b/src/disk_interface.cc @@ -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; diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc index 7041d98..294df72 100644 --- a/src/disk_interface_test.cc +++ b/src/disk_interface_test.cc @@ -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 |