Index: llvm/lib/Support/VirtualFileSystem.cpp =================================================================== --- llvm/lib/Support/VirtualFileSystem.cpp +++ llvm/lib/Support/VirtualFileSystem.cpp @@ -2066,7 +2066,8 @@ "Overlay dir must be contained in RPath"); RPath = RPath.slice(OverlayDirLen, RPath.size()); } - writeEntry(path::filename(Entry.VPath), RPath); + if (!Entry.IsDirectory) + writeEntry(path::filename(Entry.VPath), RPath); } while (!DirStack.empty()) { Index: llvm/unittests/Support/VirtualFileSystemTest.cpp =================================================================== --- llvm/unittests/Support/VirtualFileSystemTest.cpp +++ llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -2238,3 +2238,39 @@ EXPECT_TRUE(FS->exists(_g.Path)); EXPECT_TRUE(FS->exists(_h.Path)); } + +TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) { + ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true); + ScopedDir TheFirstEntry(TestDirectory + "/thefirstentry"); + ScopedDir AnotherEntry(TestDirectory + "/anotherentry"); + ScopedDir YetAnotherEntry(TestDirectory + "/yetanotherentry"); + + vfs::YAMLVFSWriter VFSWriter; + VFSWriter.addDirectoryMapping(TheFirstEntry.Path, "//root/thefirstentry"); + VFSWriter.addDirectoryMapping(AnotherEntry.Path, "//root/anotherentry"); + VFSWriter.addDirectoryMapping(YetAnotherEntry.Path, "//root/yetanotherentry"); + + std::string Buffer; + raw_string_ostream OS(Buffer); + VFSWriter.write(OS); + OS.flush(); + + // We didn't add a single file - only directories. + EXPECT_TRUE(Buffer.find("'type': 'file'") == std::string::npos); + + IntrusiveRefCntPtr Lower(new ErrorDummyFileSystem()); + Lower->addDirectory("//root/thefirstentry"); + Lower->addDirectory("//root/anotherentry"); + Lower->addDirectory("//root/yetanotherentry"); + // canaries + Lower->addRegularFile("//root/thefirstentry/thefirstentry"); + Lower->addRegularFile("//root/anotherentry/anotherentry"); + Lower->addRegularFile("//root/yetanotherentry/yetanotherentry"); + + IntrusiveRefCntPtr FS = getFromYAMLRawString(Buffer, Lower); + ASSERT_TRUE(FS.get() != nullptr); + + EXPECT_FALSE(FS->exists(TheFirstEntry.Path + "/thefirstentry")); + EXPECT_FALSE(FS->exists(AnotherEntry.Path + "/anotherentry")); + EXPECT_FALSE(FS->exists(YetAnotherEntry.Path + "/yetanotherentry")); +}