Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 6c86409

Browse files
author
Fredrik Medley
committed
Fix stat when subdirectory is a file
Make sure that stat on Windows, both with and without cache, returns "missing file" when running stat on notadir/foo where notadir is a file.
1 parent ed11516 commit 6c86409

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/disk_interface.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ bool StatAllFilesInDir(const string& dir, map<string, TimeStamp>* stamps,
105105

106106
if (find_handle == INVALID_HANDLE_VALUE) {
107107
DWORD win_err = GetLastError();
108-
if (win_err == ERROR_FILE_NOT_FOUND || win_err == ERROR_PATH_NOT_FOUND)
108+
if (win_err == ERROR_FILE_NOT_FOUND || win_err == ERROR_PATH_NOT_FOUND ||
109+
win_err == ERROR_DIRECTORY) // File and not a directory
109110
return true;
110111
*err = "FindFirstFileExA(" + dir + "): " + GetLastErrorString();
111112
return false;

src/disk_interface_test.cc

+21
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ TEST_F(DiskInterfaceTest, StatMissingFile) {
6363
EXPECT_EQ("", err);
6464
}
6565

66+
#ifdef _WIN32
67+
TEST_F(DiskInterfaceTest, StatMissingFileWithCache) {
68+
string err;
69+
disk_.AllowStatCache(true);
70+
71+
EXPECT_EQ(0, disk_.Stat("nosuchfile", &err));
72+
EXPECT_EQ("", err);
73+
74+
// On Windows, the errno for a file in a nonexistent directory
75+
// is different.
76+
EXPECT_EQ(0, disk_.Stat("nosuchdir/nosuchfile", &err));
77+
EXPECT_EQ("", err);
78+
79+
// On POSIX systems, the errno is different if a component of the
80+
// path prefix is not a directory.
81+
ASSERT_TRUE(Touch("notadir"));
82+
EXPECT_EQ(0, disk_.Stat("notadir/nosuchfile", &err));
83+
EXPECT_EQ("", err);
84+
}
85+
#endif
86+
6687
TEST_F(DiskInterfaceTest, StatBadPath) {
6788
string err;
6889
#ifdef _WIN32

0 commit comments

Comments
 (0)