From e9ffd8dfbadcf9eb0963e30be3f989b7ef70d01d Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Fri, 23 Dec 2011 10:56:04 -0800 Subject: [PATCH] windows: handle ERROR_PATH_NOT_FOUND From Frances . --- src/disk_interface.cc | 3 ++- src/disk_interface_test.cc | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/disk_interface.cc b/src/disk_interface.cc index b60cd6f..4227f8f 100644 --- a/src/disk_interface.cc +++ b/src/disk_interface.cc @@ -69,7 +69,8 @@ int RealDiskInterface::Stat(const std::string& path) { #ifdef WIN32 WIN32_FILE_ATTRIBUTE_DATA attrs; if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &attrs)) { - if (GetLastError() == ERROR_FILE_NOT_FOUND) + DWORD err = GetLastError(); + if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) return 0; Error("GetFileAttributesEx(%s): %s", path.c_str(), GetLastErrorString().c_str()); diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc index d0794fd..3bb8067 100644 --- a/src/disk_interface_test.cc +++ b/src/disk_interface_test.cc @@ -109,16 +109,17 @@ class DiskInterfaceTest : public testing::Test { TEST_F(DiskInterfaceTest, StatMissingFile) { EXPECT_EQ(0, disk_.Stat("nosuchfile")); + + // On Windows, the errno for a file in a nonexistent directory + // is different. + EXPECT_EQ(0, disk_.Stat("nosuchdir/nosuchfile")); } TEST_F(DiskInterfaceTest, StatBadPath) { -#ifdef _WIN32 - string bad_path = "cc:\\foo"; - EXPECT_EQ(-1, disk_.Stat(bad_path)); -#else + // To test the error code path, use an overlong file name. + // Both Windows and Linux appear to object to this. string too_long_name(512, 'x'); EXPECT_EQ(-1, disk_.Stat(too_long_name)); -#endif } TEST_F(DiskInterfaceTest, StatExistingFile) { -- 2.7.4