[PATCH] D79551: [YAMLVFSWriter] Fix directory handling

Jan Korous via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 7 11:21:29 PDT 2020


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0330bc00f52: [YAMLVFSWriter] Fix directory handling (authored by jkorous).

Changed prior to commit:
  https://reviews.llvm.org/D79551?vs=262544&id=262704#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79551/new/

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 _a(TestDirectory + "/a");
+  ScopedDir _b(TestDirectory + "/b");
+  ScopedDir _c(TestDirectory + "/c");
+
+  vfs::YAMLVFSWriter VFSWriter;
+  VFSWriter.addDirectoryMapping(_a.Path, "//root/a");
+  VFSWriter.addDirectoryMapping(_b.Path, "//root/b");
+  VFSWriter.addDirectoryMapping(_c.Path, "//root/c");
+
+  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/a");
+  Lower->addDirectory("//root/b");
+  Lower->addDirectory("//root/c");
+  // canaries
+  Lower->addRegularFile("//root/a/a");
+  Lower->addRegularFile("//root/b/b");
+  Lower->addRegularFile("//root/c/c");
+
+  IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
+  ASSERT_TRUE(FS.get() != nullptr);
+
+  EXPECT_FALSE(FS->exists(_a.Path + "/a"));
+  EXPECT_FALSE(FS->exists(_b.Path + "/b"));
+  EXPECT_FALSE(FS->exists(_c.Path + "/c"));
+}
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.262704.patch
Type: text/x-patch
Size: 2118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200507/05f87348/attachment.bin>


More information about the llvm-commits mailing list