[PATCH] D79551: [YAMLVFSWriter] Fix directory handling

Jan Korous via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 6 22:08:50 PDT 2020


jkorous created this revision.
jkorous added a reviewer: JDevlieghere.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.

For empty directories (except the first one) we've been adding a file with the same name as the directory to the result VFS mapping.


https://reviews.llvm.org/D79551

Files:
  llvm/lib/Support/VirtualFileSystem.cpp
  llvm/unittests/Support/VirtualFileSystemTest.cpp


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<ErrorDummyFileSystem> 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<vfs::FileSystem> 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"));
+}
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()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79551.262544.patch
Type: text/x-patch
Size: 2442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200507/591b9bf9/attachment.bin>


More information about the llvm-commits mailing list