]> granicus.if.org Git - clang/commitdiff
Revert "Reapply [VFS] Ignore broken symlinks in the directory iterator."
authorJuergen Ributzka <juergen@apple.com>
Sat, 11 Mar 2017 00:14:50 +0000 (00:14 +0000)
committerJuergen Ributzka <juergen@apple.com>
Sat, 11 Mar 2017 00:14:50 +0000 (00:14 +0000)
Still broken on Windows and SystemZ bot ... sorry for the noise.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297533 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/VirtualFileSystem.h
lib/Basic/VirtualFileSystem.cpp
unittests/Basic/VirtualFileSystemTest.cpp

index e52b345e286c694e283f1a52a563d87281ce9574..39dab6cbf045898cacde635ec10647395d652911 100644 (file)
@@ -161,7 +161,7 @@ public:
   directory_iterator &increment(std::error_code &EC) {
     assert(Impl && "attempting to increment past end");
     EC = Impl->increment();
-    if (!Impl->CurrentEntry.isStatusKnown())
+    if (EC || !Impl->CurrentEntry.isStatusKnown())
       Impl.reset(); // Normalize the end iterator to Impl == nullptr.
     return *this;
   }
index f5db717866a95a7914d2bbe11123fe661aa1ffd3..43cd9f17ceb7a60284513720aae54d157f59296f 100644 (file)
@@ -244,7 +244,8 @@ public:
     if (!EC && Iter != llvm::sys::fs::directory_iterator()) {
       llvm::sys::fs::file_status S;
       EC = Iter->status(S);
-      CurrentEntry = Status::copyWithNewName(S, Iter->path());
+      if (!EC)
+        CurrentEntry = Status::copyWithNewName(S, Iter->path());
     }
   }
 
@@ -1855,7 +1856,7 @@ vfs::recursive_directory_iterator::recursive_directory_iterator(FileSystem &FS_,
                                                            std::error_code &EC)
     : FS(&FS_) {
   directory_iterator I = FS->dir_begin(Path, EC);
-  if (I != directory_iterator()) {
+  if (!EC && I != directory_iterator()) {
     State = std::make_shared<IterState>();
     State->push(I);
   }
@@ -1868,6 +1869,8 @@ recursive_directory_iterator::increment(std::error_code &EC) {
   vfs::directory_iterator End;
   if (State->top()->isDirectory()) {
     vfs::directory_iterator I = FS->dir_begin(State->top()->getName(), EC);
+    if (EC)
+      return *this;
     if (I != End) {
       State->push(I);
       return *this;
index ea00bf599374eeff8a4d0d8c08df19bc6ff66f0d..580343d93ea1f0d6e02268679cf97b0aa1c3b36d 100644 (file)
@@ -305,22 +305,6 @@ struct ScopedDir {
   }
   operator StringRef() { return Path.str(); }
 };
-
-struct ScopedLink {
-  SmallString<128> Path;
-  ScopedLink(const Twine &To, const Twine &From) {
-    Path = From.str();
-    std::error_code EC = sys::fs::create_link(To, From);
-    if (EC)
-      Path = "";
-    EXPECT_FALSE(EC);
-  }
-  ~ScopedLink() {
-    if (Path != "")
-      EXPECT_FALSE(llvm::sys::fs::remove(Path.str()));
-  }
-  operator StringRef() { return Path.str(); }
-};
 } // end anonymous namespace
 
 TEST(VirtualFileSystemTest, BasicRealFSIteration) {
@@ -350,28 +334,6 @@ TEST(VirtualFileSystemTest, BasicRealFSIteration) {
   EXPECT_EQ(vfs::directory_iterator(), I);
 }
 
-TEST(VirtualFileSystemTest, BrokenSymlinkRealFSIteration) {
-  ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
-  IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
-
-  ScopedLink _a("no_such_file", TestDirectory + "/a");
-  ScopedDir _b(TestDirectory + "/b");
-  ScopedLink _c("no_such_file", TestDirectory + "/c");
-
-  std::error_code EC;
-  for (vfs::directory_iterator I = FS->dir_begin(Twine(TestDirectory), EC), E;
-       I != E; I.increment(EC)) {
-    // Skip broken symlinks.
-    if (EC == std::errc::no_such_file_or_directory) {
-      EC = std::error_code();
-      continue;
-    } else if (EC) {
-      break;
-    }
-    EXPECT_TRUE(I->getName() == _b);
-  }
-}
-
 TEST(VirtualFileSystemTest, BasicRealFSRecursiveIteration) {
   ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/true);
   IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
@@ -411,43 +373,6 @@ TEST(VirtualFileSystemTest, BasicRealFSRecursiveIteration) {
   EXPECT_EQ(1, Counts[3]); // d
 }
 
-TEST(VirtualFileSystemTest, BrokenSymlinkRealFSRecursiveIteration) {
-  ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
-  IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
-
-  ScopedLink _a("no_such_file", TestDirectory + "/a");
-  ScopedDir _b(TestDirectory + "/b");
-  ScopedLink _ba("no_such_file", TestDirectory + "/b/a");
-  ScopedDir _bb(TestDirectory + "/b/b");
-  ScopedLink _bc("no_such_file", TestDirectory + "/b/c");
-  ScopedLink _c("no_such_file", TestDirectory + "/c");
-  ScopedDir _d(TestDirectory + "/d");
-  ScopedDir _dd(TestDirectory + "/d/d");
-  ScopedDir _ddd(TestDirectory + "/d/d/d");
-  ScopedLink _e("no_such_file", TestDirectory + "/e");
-  std::vector<StringRef> Expected = {_b, _bb, _d, _dd, _ddd};
-
-  std::vector<std::string> Contents;
-  std::error_code EC;
-  for (vfs::recursive_directory_iterator I(*FS, Twine(TestDirectory), EC), E;
-       I != E; I.increment(EC)) {
-    // Skip broken symlinks.
-    if (EC == std::errc::no_such_file_or_directory) {
-      EC = std::error_code();
-      continue;
-    } else if (EC) {
-      outs() << "BrokenSymlinkRealFSRecursiveIteration EC: " << EC.message();
-      break;
-    }
-    Contents.push_back(I->getName());
-  }
-
-  // Check sorted contents.
-  std::sort(Contents.begin(), Contents.end());
-  EXPECT_EQ(Expected.size(), Contents.size());
-  EXPECT_TRUE(std::equal(Contents.begin(), Contents.end(), Expected.begin()));
-}
-
 template <typename DirIter>
 static void checkContents(DirIter I, ArrayRef<StringRef> ExpectedOut) {
   std::error_code EC;