Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit a6015a4

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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364986 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 3dc9416)
1 parent a1524e8 commit a6015a4

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

include/llvm/Support/VirtualFileSystem.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,24 @@ class OverlayFileSystem : public FileSystem {
336336

337337
using iterator = FileSystemList::reverse_iterator;
338338
using const_iterator = FileSystemList::const_reverse_iterator;
339+
using reverse_iterator = FileSystemList::iterator;
340+
using const_reverse_iterator = FileSystemList::const_iterator;
339341

340342
/// Get an iterator pointing to the most recently added file system.
341343
iterator overlays_begin() { return FSList.rbegin(); }
342344
const_iterator overlays_begin() const { return FSList.rbegin(); }
343345

344-
/// Get an iterator pointing one-past the least recently added file
345-
/// system.
346+
/// Get an iterator pointing one-past the least recently added file system.
346347
iterator overlays_end() { return FSList.rend(); }
347348
const_iterator overlays_end() const { return FSList.rend(); }
349+
350+
/// Get an iterator pointing to the least recently added file system.
351+
reverse_iterator overlays_rbegin() { return FSList.begin(); }
352+
const_reverse_iterator overlays_rbegin() const { return FSList.begin(); }
353+
354+
/// Get an iterator pointing one-past the most recently added file system.
355+
reverse_iterator overlays_rend() { return FSList.end(); }
356+
const_reverse_iterator overlays_rend() const { return FSList.end(); }
348357
};
349358

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

unittests/Support/VirtualFileSystemTest.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,57 @@ TEST(VirtualFileSystemTest, MergedDirPermissions) {
343343
EXPECT_EQ(0200, Status->getPermissions());
344344
}
345345

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

0 commit comments

Comments
 (0)