[PATCH] D54455: [vfs] add 'Status::copyWithNewSize'
Alex Lorenz via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 12 15:47:13 PST 2018
arphaman created this revision.
arphaman added a reviewer: JDevlieghere.
Herald added subscribers: kristina, kadircet, dexonsmith, ioeric, ilya-biryukov.
This patch adds a `Status::copyWithNewSize` method to `vfs::Status`. It allows the user to duplicate a status object with a different size.
This is part of the work for upstreaming `clang-scan-deps`, see https://reviews.llvm.org/D53354 and `[cfe-dev] RFC: prototype of clang-scan-deps, faster dependency scanning tool for explicit modules and clangd`.
Repository:
rL LLVM
https://reviews.llvm.org/D54455
Files:
include/llvm/Support/VirtualFileSystem.h
lib/Support/VirtualFileSystem.cpp
unittests/Support/VirtualFileSystemTest.cpp
Index: unittests/Support/VirtualFileSystemTest.cpp
===================================================================
--- unittests/Support/VirtualFileSystemTest.cpp
+++ unittests/Support/VirtualFileSystemTest.cpp
@@ -1775,3 +1775,14 @@
checkContents(FS->dir_begin("//root/foo", EC),
{"//root/foo/a", "//root/foo/b"});
}
+
+TEST_F(InMemoryFileSystemTest, CopyStatusWithSize) {
+ FS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a"));
+ auto Stat = FS.status("/a");
+ ASSERT_TRUE(Stat);
+ auto CopyStat = vfs::Status::copyWithNewSize(*Stat, 2);
+ ASSERT_EQ(CopyStat.getSize(), 2u);
+ ASSERT_NE(CopyStat.getSize(), Stat->getSize());
+ ASSERT_EQ(CopyStat.getName(), Stat->getName());
+ ASSERT_EQ(CopyStat.getUniqueID(), Stat->getUniqueID());
+}
Index: lib/Support/VirtualFileSystem.cpp
===================================================================
--- lib/Support/VirtualFileSystem.cpp
+++ lib/Support/VirtualFileSystem.cpp
@@ -85,6 +85,12 @@
In.permissions());
}
+Status Status::copyWithNewSize(const Status &In, uint64_t Size) {
+ return Status(In.getName(), In.getUniqueID(), In.getLastModificationTime(),
+ In.getUser(), In.getGroup(), Size, In.getType(),
+ In.getPermissions());
+}
+
bool Status::equivalent(const Status &Other) const {
assert(isStatusKnown() && Other.isStatusKnown());
return getUniqueID() == Other.getUniqueID();
Index: include/llvm/Support/VirtualFileSystem.h
===================================================================
--- include/llvm/Support/VirtualFileSystem.h
+++ include/llvm/Support/VirtualFileSystem.h
@@ -67,6 +67,7 @@
static Status copyWithNewName(const Status &In, StringRef NewName);
static Status copyWithNewName(const llvm::sys::fs::file_status &In,
StringRef NewName);
+ static Status copyWithNewSize(const Status &In, uint64_t Size);
/// Returns the name that should be used for this file or directory.
StringRef getName() const { return Name; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54455.173778.patch
Type: text/x-patch
Size: 2033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181112/7323e70c/attachment-0001.bin>
More information about the llvm-commits
mailing list