llvm.org GIT mirror llvm / 3dc9416
[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 Jonas Devlieghere 3 months ago
2 changed file(s) with 62 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
342342
343343 using iterator = FileSystemList::reverse_iterator;
344344 using const_iterator = FileSystemList::const_reverse_iterator;
345 using reverse_iterator = FileSystemList::iterator;
346 using const_reverse_iterator = FileSystemList::const_iterator;
345347
346348 /// Get an iterator pointing to the most recently added file system.
347349 iterator overlays_begin() { return FSList.rbegin(); }
348350 const_iterator overlays_begin() const { return FSList.rbegin(); }
349351
350 /// Get an iterator pointing one-past the least recently added file
351 /// system.
352 /// Get an iterator pointing one-past the least recently added file system.
352353 iterator overlays_end() { return FSList.rend(); }
353354 const_iterator overlays_end() const { return FSList.rend(); }
355
356 /// Get an iterator pointing to the least recently added file system.
357 reverse_iterator overlays_rbegin() { return FSList.begin(); }
358 const_reverse_iterator overlays_rbegin() const { return FSList.begin(); }
359
360 /// Get an iterator pointing one-past the most recently added file system.
361 reverse_iterator overlays_rend() { return FSList.end(); }
362 const_reverse_iterator overlays_rend() const { return FSList.end(); }
354363 };
355364
356365 /// By default, this delegates all calls to the underlying file system. This
341341 EXPECT_EQ(0200, Status->getPermissions());
342342 }
343343
344 TEST(VirtualFileSystemTest, OverlayIterator) {
345 IntrusiveRefCntPtr Lower(new DummyFileSystem());
346 Lower->addRegularFile("/foo");
347 IntrusiveRefCntPtr Upper(new DummyFileSystem());
348
349 IntrusiveRefCntPtr O(
350 new vfs::OverlayFileSystem(Lower));
351 O->pushOverlay(Upper);
352
353 ErrorOr Status((std::error_code()));
354 {
355 auto it = O->overlays_begin();
356 auto end = O->overlays_end();
357
358 EXPECT_NE(it, end);
359
360 Status = (*it)->status("/foo");
361 ASSERT_TRUE(Status.getError());
362
363 it++;
364 EXPECT_NE(it, end);
365
366 Status = (*it)->status("/foo");
367 ASSERT_FALSE(Status.getError());
368 EXPECT_TRUE(Status->exists());
369
370 it++;
371 EXPECT_EQ(it, end);
372 }
373
374 {
375 auto it = O->overlays_rbegin();
376 auto end = O->overlays_rend();
377
378 EXPECT_NE(it, end);
379
380 Status = (*it)->status("/foo");
381 ASSERT_FALSE(Status.getError());
382 EXPECT_TRUE(Status->exists());
383
384 it++;
385 EXPECT_NE(it, end);
386
387 Status = (*it)->status("/foo");
388 ASSERT_TRUE(Status.getError());
389
390 it++;
391 EXPECT_EQ(it, end);
392 }
393 }
394
344395 namespace {
345396 struct ScopedDir {
346397 SmallString<128> Path;