summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2012-03-08 07:03:50 (GMT)
committerEvan Martin <martine@danga.com>2012-03-08 07:03:50 (GMT)
commite4bc7e25a31f695d14930e931a225b315d96de75 (patch)
tree5d6182adefd48be140117585d3a532d7c5c74a29 /src
parent28ef3b736ef3fa84f65f95f81ac686eb6a299f82 (diff)
parent1d25f6b54773c739340361902b7d1412f53ef7fc (diff)
downloadNinja-e4bc7e25a31f695d14930e931a225b315d96de75.zip
Ninja-e4bc7e25a31f695d14930e931a225b315d96de75.tar.gz
Ninja-e4bc7e25a31f695d14930e931a225b315d96de75.tar.bz2
Merge pull request #239 from pcc/enotdir
Treat paths of the form "existing-file/something" as non-existent
Diffstat (limited to 'src')
-rw-r--r--src/disk_interface.cc2
-rw-r--r--src/disk_interface_test.cc26
2 files changed, 15 insertions, 13 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc
index 96a1e59..b1a1746 100644
--- a/src/disk_interface.cc
+++ b/src/disk_interface.cc
@@ -94,7 +94,7 @@ TimeStamp RealDiskInterface::Stat(const string& path) {
#else
struct stat st;
if (stat(path.c_str(), &st) < 0) {
- if (errno == ENOENT)
+ if (errno == ENOENT || errno == ENOTDIR)
return 0;
Error("stat(%s): %s", path.c_str(), strerror(errno));
return -1;
diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc
index 052a94b..67e2a04 100644
--- a/src/disk_interface_test.cc
+++ b/src/disk_interface_test.cc
@@ -36,6 +36,13 @@ class DiskInterfaceTest : public testing::Test {
temp_dir_.Cleanup();
}
+ bool Touch(const char* path) {
+ FILE *f = fopen(path, "w");
+ if (!f)
+ return false;
+ return fclose(f) == 0;
+ }
+
ScopedTempDir temp_dir_;
RealDiskInterface disk_;
};
@@ -46,6 +53,11 @@ TEST_F(DiskInterfaceTest, StatMissingFile) {
// On Windows, the errno for a file in a nonexistent directory
// is different.
EXPECT_EQ(0, disk_.Stat("nosuchdir/nosuchfile"));
+
+ // On POSIX systems, the errno is different if a component of the
+ // path prefix is not a directory.
+ ASSERT_TRUE(Touch("notadir"));
+ EXPECT_EQ(0, disk_.Stat("notadir/nosuchfile"));
}
TEST_F(DiskInterfaceTest, StatBadPath) {
@@ -56,11 +68,7 @@ TEST_F(DiskInterfaceTest, StatBadPath) {
}
TEST_F(DiskInterfaceTest, StatExistingFile) {
-#ifdef _WIN32
- ASSERT_EQ(0, system("cmd.exe /c echo hi > file"));
-#else
- ASSERT_EQ(0, system("touch file"));
-#endif
+ ASSERT_TRUE(Touch("file"));
EXPECT_GT(disk_.Stat("file"), 1);
}
@@ -86,13 +94,7 @@ TEST_F(DiskInterfaceTest, MakeDirs) {
TEST_F(DiskInterfaceTest, RemoveFile) {
const char* kFileName = "file-to-remove";
-#ifdef _WIN32
- string cmd = "cmd /c echo hi > ";
-#else
- string cmd = "touch ";
-#endif
- cmd += kFileName;
- ASSERT_EQ(0, system(cmd.c_str()));
+ ASSERT_TRUE(Touch(kFileName));
EXPECT_EQ(0, disk_.RemoveFile(kFileName));
EXPECT_EQ(1, disk_.RemoveFile(kFileName));
EXPECT_EQ(1, disk_.RemoveFile("does not exist"));