diff options
author | Ben Langmuir <blangmuir@apple.com> | 2023-04-25 11:04:06 -0700 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2023-05-02 09:39:07 -0700 |
commit | 5437a4c5e90886c6688da90eaf70617d50e64895 (patch) | |
tree | e1cc1410611cac53bc7221e8fe1a69eb2f089158 /llvm/unittests/Support/VirtualFileSystemTest.cpp | |
parent | 64888d437c9e0dd52adad9b26784369a4ea24b7f (diff) | |
download | llvm-5437a4c5e90886c6688da90eaf70617d50e64895.zip llvm-5437a4c5e90886c6688da90eaf70617d50e64895.tar.gz llvm-5437a4c5e90886c6688da90eaf70617d50e64895.tar.bz2 |
[llvm][vfs] Avoid silent fallback to process-wide working directory
In createPhysicalFileSystem, preserve the per-instance working
directory, even after the first call to getcwd fails.
rdar://108213753
Differential Revision: https://reviews.llvm.org/D149173
Diffstat (limited to 'llvm/unittests/Support/VirtualFileSystemTest.cpp')
-rw-r--r-- | llvm/unittests/Support/VirtualFileSystemTest.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index d31674a..cfbb81e 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/VirtualFileSystem.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/Config/llvm-config.h" #include "llvm/Support/Errc.h" #include "llvm/Support/MemoryBuffer.h" @@ -526,6 +527,31 @@ TEST(VirtualFileSystemTest, MultipleWorkingDirs) { ASSERT_EQ(CIt, vfs::directory_iterator()); } +TEST(VirtualFileSystemTest, PhysicalFileSystemWorkingDirFailure) { + TempDir D2("d2", /*Unique*/ true); + SmallString<128> WD, PrevWD; + ASSERT_EQ(sys::fs::current_path(PrevWD), std::error_code()); + ASSERT_EQ(sys::fs::createUniqueDirectory("d1", WD), std::error_code()); + ASSERT_EQ(sys::fs::set_current_path(WD), std::error_code()); + auto Restore = + llvm::make_scope_exit([&] { sys::fs::set_current_path(PrevWD); }); + + // Delete the working directory to create an error. + ASSERT_EQ(sys::fs::remove_directories(WD), std::error_code()); + + // Verify that we still get two separate working directories. + auto FS1 = vfs::createPhysicalFileSystem(); + auto FS2 = vfs::createPhysicalFileSystem(); + ASSERT_EQ(FS1->getCurrentWorkingDirectory().getError(), + errc::no_such_file_or_directory); + ASSERT_EQ(FS1->setCurrentWorkingDirectory(D2.path()), std::error_code()); + ASSERT_EQ(FS1->getCurrentWorkingDirectory().get(), D2.path()); + EXPECT_EQ(FS2->getCurrentWorkingDirectory().getError(), + errc::no_such_file_or_directory); + SmallString<128> WD2; + EXPECT_EQ(sys::fs::current_path(WD2), errc::no_such_file_or_directory); +} + TEST(VirtualFileSystemTest, BrokenSymlinkRealFSIteration) { TempDir TestDirectory("virtual-file-system-test", /*Unique*/ true); IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem(); |