This repository was archived by the owner on Mar 28, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +62
-2
lines changed Expand file tree Collapse file tree 2 files changed +62
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+
346397namespace {
347398struct ScopedDir {
348399 SmallString<128 > Path;
You can’t perform that action at this time.
0 commit comments