]> granicus.if.org Git - clang/commitdiff
[VFS] Don't try to be heroic with '.' in paths.
authorBenjamin Kramer <benny.kra@googlemail.com>
Mon, 12 Oct 2015 13:30:38 +0000 (13:30 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Mon, 12 Oct 2015 13:30:38 +0000 (13:30 +0000)
Actually the only special path we have to handle is ./foo, the rest is
tricky to get right so do the same thing as the existing YAML vfs here.

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

lib/Basic/VirtualFileSystem.cpp
unittests/Basic/VirtualFileSystemTest.cpp

index cb09e2ec84f326e9f1bc16a06c9cc68ee8a8ee99..1b75fbefd2ae63c19961e895cac862212c97632f 100644 (file)
@@ -10,7 +10,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Basic/VirtualFileSystem.h"
-#include "clang/Basic/FileManager.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
@@ -497,12 +496,14 @@ void InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
   assert(!EC);
   (void)EC;
 
-  FileManager::removeDotPaths(Path, /*RemoveDotDot=*/false);
-  if (Path.empty())
-    return;
-
   detail::InMemoryDirectory *Dir = Root.get();
   auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path);
+  if (*I == ".")
+    ++I;
+
+  if (I == E)
+    return;
+
   while (true) {
     StringRef Name = *I;
     detail::InMemoryNode *Node = Dir->getChild(Name);
@@ -556,11 +557,13 @@ lookupInMemoryNode(const InMemoryFileSystem &FS, detail::InMemoryDirectory *Dir,
   assert(!EC);
   (void)EC;
 
-  FileManager::removeDotPaths(Path, /*RemoveDotDot=*/false);
-  if (Path.empty())
+  auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path);
+  if (*I == ".")
+    ++I;
+
+  if (I == E)
     return Dir;
 
-  auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path);
   while (true) {
     detail::InMemoryNode *Node = Dir->getChild(*I);
     ++I;
index 6ed811f22f3f9725b95d101534623841935b0a01..16c2096c991657ea468ae500dfe3fa9c8f88b21b 100644 (file)
@@ -551,8 +551,6 @@ TEST_F(InMemoryFileSystemTest, OverlayFile) {
   FS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a"));
   auto Stat = FS.status("/");
   ASSERT_FALSE(Stat.getError()) << Stat.getError() << FS.toString();
-  Stat = FS.status("/.");
-  ASSERT_FALSE(Stat.getError()) << Stat.getError() << FS.toString();
   Stat = FS.status("/a");
   ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
   ASSERT_EQ("/a", Stat->getName());
@@ -568,18 +566,18 @@ TEST_F(InMemoryFileSystemTest, OverlayFileNoOwn) {
 
 TEST_F(InMemoryFileSystemTest, OpenFileForRead) {
   FS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a"));
-  FS.addFile("././c", 0, MemoryBuffer::getMemBuffer("c"));
+  FS.addFile("./c", 0, MemoryBuffer::getMemBuffer("c"));
   auto File = FS.openFileForRead("/a");
   ASSERT_EQ("a", (*(*File)->getBuffer("ignored"))->getBuffer());
   File = FS.openFileForRead("/a"); // Open again.
   ASSERT_EQ("a", (*(*File)->getBuffer("ignored"))->getBuffer());
-  File = FS.openFileForRead("/././a"); // Open again.
+  File = FS.openFileForRead("./a"); // Open again.
   ASSERT_EQ("a", (*(*File)->getBuffer("ignored"))->getBuffer());
   File = FS.openFileForRead("/");
   ASSERT_EQ(File.getError(), errc::invalid_argument) << FS.toString();
   File = FS.openFileForRead("/b");
   ASSERT_EQ(File.getError(), errc::no_such_file_or_directory) << FS.toString();
-  File = FS.openFileForRead("./c");
+  File = FS.openFileForRead("c");
   ASSERT_EQ("c", (*(*File)->getBuffer("ignored"))->getBuffer());
 }