File tree 2 files changed +62
-2
lines changed
2 files changed +62
-2
lines changed Original file line number Diff line number Diff line change @@ -343,15 +343,24 @@ class OverlayFileSystem : public FileSystem {
343
343
344
344
using iterator = FileSystemList::reverse_iterator;
345
345
using const_iterator = FileSystemList::const_reverse_iterator;
346
+ using reverse_iterator = FileSystemList::iterator;
347
+ using const_reverse_iterator = FileSystemList::const_iterator;
346
348
347
349
// / Get an iterator pointing to the most recently added file system.
348
350
iterator overlays_begin () { return FSList.rbegin (); }
349
351
const_iterator overlays_begin () const { return FSList.rbegin (); }
350
352
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.
353
354
iterator overlays_end () { return FSList.rend (); }
354
355
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 (); }
355
364
};
356
365
357
366
// / By default, this delegates all calls to the underlying file system. This
Original file line number Diff line number Diff line change @@ -342,6 +342,57 @@ TEST(VirtualFileSystemTest, MergedDirPermissions) {
342
342
EXPECT_EQ (0200 , Status->getPermissions ());
343
343
}
344
344
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
+
345
396
namespace {
346
397
struct ScopedDir {
347
398
SmallString<128 > Path;
You can’t perform that action at this time.
0 commit comments