Skip to content

Commit efe2108

Browse files
committed
[VFS] Add reverse iterator to OverlayFileSystem
Add a reverse iterator to the overlay file system. This makes it possible to take overlays from one OverlayFileSystem, and add them to another. Differential revision: https://reviews.llvm.org/D64113 llvm-svn: 364986
1 parent b88ebe8 commit efe2108

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

llvm/include/llvm/Support/VirtualFileSystem.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,24 @@ class OverlayFileSystem : public FileSystem {
343343

344344
using iterator = FileSystemList::reverse_iterator;
345345
using const_iterator = FileSystemList::const_reverse_iterator;
346+
using reverse_iterator = FileSystemList::iterator;
347+
using const_reverse_iterator = FileSystemList::const_iterator;
346348

347349
/// Get an iterator pointing to the most recently added file system.
348350
iterator overlays_begin() { return FSList.rbegin(); }
349351
const_iterator overlays_begin() const { return FSList.rbegin(); }
350352

351-
/// Get an iterator pointing one-past the least recently added file
352-
/// system.
353+
/// Get an iterator pointing one-past the least recently added file system.
353354
iterator overlays_end() { return FSList.rend(); }
354355
const_iterator overlays_end() const { return FSList.rend(); }
356+
357+
/// Get an iterator pointing to the least recently added file system.
358+
reverse_iterator overlays_rbegin() { return FSList.begin(); }
359+
const_reverse_iterator overlays_rbegin() const { return FSList.begin(); }
360+
361+
/// Get an iterator pointing one-past the most recently added file system.
362+
reverse_iterator overlays_rend() { return FSList.end(); }
363+
const_reverse_iterator overlays_rend() const { return FSList.end(); }
355364
};
356365

357366
/// By default, this delegates all calls to the underlying file system. This

llvm/unittests/Support/VirtualFileSystemTest.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,57 @@ TEST(VirtualFileSystemTest, MergedDirPermissions) {
342342
EXPECT_EQ(0200, Status->getPermissions());
343343
}
344344

345+
TEST(VirtualFileSystemTest, OverlayIterator) {
346+
IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
347+
Lower->addRegularFile("/foo");
348+
IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem());
349+
350+
IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
351+
new vfs::OverlayFileSystem(Lower));
352+
O->pushOverlay(Upper);
353+
354+
ErrorOr<vfs::Status> Status((std::error_code()));
355+
{
356+
auto it = O->overlays_begin();
357+
auto end = O->overlays_end();
358+
359+
EXPECT_NE(it, end);
360+
361+
Status = (*it)->status("/foo");
362+
ASSERT_TRUE(Status.getError());
363+
364+
it++;
365+
EXPECT_NE(it, end);
366+
367+
Status = (*it)->status("/foo");
368+
ASSERT_FALSE(Status.getError());
369+
EXPECT_TRUE(Status->exists());
370+
371+
it++;
372+
EXPECT_EQ(it, end);
373+
}
374+
375+
{
376+
auto it = O->overlays_rbegin();
377+
auto end = O->overlays_rend();
378+
379+
EXPECT_NE(it, end);
380+
381+
Status = (*it)->status("/foo");
382+
ASSERT_FALSE(Status.getError());
383+
EXPECT_TRUE(Status->exists());
384+
385+
it++;
386+
EXPECT_NE(it, end);
387+
388+
Status = (*it)->status("/foo");
389+
ASSERT_TRUE(Status.getError());
390+
391+
it++;
392+
EXPECT_EQ(it, end);
393+
}
394+
}
395+
345396
namespace {
346397
struct ScopedDir {
347398
SmallString<128> Path;

0 commit comments

Comments
 (0)