diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2021-01-22 13:51:59 -0800 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2021-01-22 14:15:48 -0800 |
commit | 0be9ca7c0f9a733f846bb6bc4e8e36d46b518162 (patch) | |
tree | c06c412ebbee9629bcd77f4ceae65c83b6d8db4a /llvm/unittests/Support/VirtualFileSystemTest.cpp | |
parent | 2bb92bf451d7eb2c817f3e5403353e7c0c14d350 (diff) | |
download | llvm-0be9ca7c0f9a733f846bb6bc4e8e36d46b518162.zip llvm-0be9ca7c0f9a733f846bb6bc4e8e36d46b518162.tar.gz llvm-0be9ca7c0f9a733f846bb6bc4e8e36d46b518162.tar.bz2 |
[VFS] Fix inconsistencies between relative paths and fallthrough.
This patch addresses inconsistencies in the way fallthrough is handled
in the RedirectingFileSystem. Rather than trying to change the working
directory of the external filesystem, the RedirectingFileSystem will
canonicalize every path before handing it down. This guarantees that
relative paths are resolved relative to the RedirectingFileSystem's
working directory.
This allows us to have a strictly virtual working directory, and still
fallthrough for absolute paths, but not for relative paths that would
get resolved incorrectly at the lower layer (for example, in case of the
RealFileSystem, because the strictly virtual path does not exist).
Differential revision: https://reviews.llvm.org/D95188
Diffstat (limited to 'llvm/unittests/Support/VirtualFileSystemTest.cpp')
-rw-r--r-- | llvm/unittests/Support/VirtualFileSystemTest.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index 6aff06b..86b7474 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -2135,7 +2135,41 @@ TEST_F(VFSFromYAMLTest, WorkingDirectoryFallthroughInvalid) { EXPECT_TRUE(Status->exists()); Status = FS->status("foo/a"); - ASSERT_TRUE(Status.getError()); + ASSERT_FALSE(Status.getError()); + EXPECT_TRUE(Status->exists()); +} + +TEST_F(VFSFromYAMLTest, VirtualWorkingDirectory) { + IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem()); + Lower->addDirectory("//root/"); + Lower->addDirectory("//root/foo"); + Lower->addRegularFile("//root/foo/a"); + Lower->addRegularFile("//root/foo/b"); + Lower->addRegularFile("//root/c"); + IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString( + "{ 'use-external-names': false,\n" + " 'roots': [\n" + "{\n" + " 'type': 'directory',\n" + " 'name': '//root/bar',\n" + " 'contents': [ {\n" + " 'type': 'file',\n" + " 'name': 'a',\n" + " 'external-contents': '//root/foo/a'\n" + " }\n" + " ]\n" + "}\n" + "]\n" + "}", + Lower); + ASSERT_TRUE(FS.get() != nullptr); + std::error_code EC = FS->setCurrentWorkingDirectory("//root/bar"); + ASSERT_FALSE(EC); + ASSERT_TRUE(FS.get() != nullptr); + + llvm::ErrorOr<vfs::Status> Status = FS->status("a"); + ASSERT_FALSE(Status.getError()); + EXPECT_TRUE(Status->exists()); } TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest) { |