/// Add a buffer to the VFS with a path. The VFS does not own the buffer.
void addFileNoOwn(const Twine &Path, time_t ModificationTime,
llvm::MemoryBuffer *Buffer);
- StringRef toString() const;
+ std::string toString() const;
llvm::ErrorOr<Status> status(const Twine &Path) override;
llvm::ErrorOr<std::unique_ptr<File>>
//===----------------------------------------------------------------------===//
#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"
InMemoryFileSystem::~InMemoryFileSystem() {}
-StringRef InMemoryFileSystem::toString() const {
+std::string InMemoryFileSystem::toString() const {
return Root->toString(/*Indent=*/0);
}
assert(!EC);
(void)EC;
+ FileManager::removeDotPaths(Path, /*RemoveDotDot=*/true);
+ if (Path.empty())
+ return;
+
detail::InMemoryDirectory *Dir = Root.get();
auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path);
while (true) {
StringRef Name = *I;
- // Skip over ".".
- // FIXME: Also handle "..".
- if (Name == ".") {
- ++I;
- continue;
- }
-
detail::InMemoryNode *Node = Dir->getChild(Name);
++I;
if (!Node) {
assert(!EC);
(void)EC;
+ FileManager::removeDotPaths(Path, /*RemoveDotDot=*/true);
+ if (Path.empty())
+ return Dir;
+
auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path);
while (true) {
- // Skip over ".".
- // FIXME: Also handle "..".
- if (*I == ".") {
- ++I;
- if (I == E)
- return Dir;
- continue;
- }
-
detail::InMemoryNode *Node = Dir->getChild(*I);
++I;
if (!Node)
TEST_F(InMemoryFileSystemTest, OpenFileForRead) {
FS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a"));
FS.addFile("././c", 0, MemoryBuffer::getMemBuffer("c"));
+ FS.addFile("./d/../d", 0, MemoryBuffer::getMemBuffer("d"));
auto File = FS.openFileForRead("/a");
ASSERT_EQ("a", (*(*File)->getBuffer("ignored"))->getBuffer());
File = FS.openFileForRead("/a"); // Open again.
ASSERT_EQ(File.getError(), errc::no_such_file_or_directory) << FS.toString();
File = FS.openFileForRead("./c");
ASSERT_EQ("c", (*(*File)->getBuffer("ignored"))->getBuffer());
+ File = FS.openFileForRead("e/../d");
+ ASSERT_EQ("d", (*(*File)->getBuffer("ignored"))->getBuffer());
}
TEST_F(InMemoryFileSystemTest, DirectoryIteration) {