Skip to content

Commit

Permalink
refs #12, added more tests to recursive directory iterator, fixed add…
Browse files Browse the repository at this point in the history
…itional issue with pop().
  • Loading branch information
gulrak committed May 4, 2019
1 parent cce8c43 commit 5ea3348
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 19 deletions.
3 changes: 2 additions & 1 deletion include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4885,10 +4885,11 @@ GHC_INLINE void recursive_directory_iterator::pop(std::error_code& ec)
*this = recursive_directory_iterator();
}
else {
while (depth() && _impl->_dir_iter_stack.top() == directory_iterator()) {
do {
_impl->_dir_iter_stack.pop();
_impl->_dir_iter_stack.top().increment(ec);
}
while (depth() && _impl->_dir_iter_stack.top() == directory_iterator());
}
}

Expand Down
81 changes: 63 additions & 18 deletions test/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <random>
#include <sstream>
#include <thread>
Expand Down Expand Up @@ -1205,29 +1206,73 @@ TEST_CASE("30.10.14 class recursive_directory_iterator", "[filesystem][recursive
fs::recursive_directory_iterator rd5;
rd5 = rd4;
}
/*
if(1) {
fs::path d = "..";
int maxDepth = 2;
fs::recursive_directory_iterator dit(d);
std::cout << d << std::endl;
for(auto & f : dit) {
#if 1
if(dit.depth()<=maxDepth) {
std::cout << dit.depth() << ": " << f.path() << std::endl;
{
TemporaryDirectory t(TempOpt::change_path);
generateFile("a");
fs::create_directory("d1");
fs::create_directory("d1/d2");
generateFile("d1/b");
generateFile("d1/c");
generateFile("d1/d2/d");
generateFile("e");
auto iter = fs::recursive_directory_iterator(".");
std::multimap<std::string, int> result;
while(iter != fs::recursive_directory_iterator()) {
result.insert(std::make_pair(iter->path().string(), iter.depth()));
++iter;
}
std::stringstream os;
for(auto p : result) {
os << "[" << p.first << "," << p.second << "],";
}
CHECK(os.str() == "[./a,0],[./d1,0],[./d1/b,1],[./d1/c,1],[./d1/d2,1],[./d1/d2/d,2],[./e,0],");
}
{
TemporaryDirectory t(TempOpt::change_path);
generateFile("a");
fs::create_directory("d1");
fs::create_directory("d1/d2");
generateFile("d1/d2/b");
generateFile("e");
auto iter = fs::recursive_directory_iterator(".");
std::multimap<std::string, int> result;
while(iter != fs::recursive_directory_iterator()) {
result.insert(std::make_pair(iter->path().string(), iter.depth()));
if(iter->path() == "./d1/d2") {
iter.disable_recursion_pending();
}
else {
dit.pop();
++iter;
}
std::stringstream os;
for(auto p : result) {
os << "[" << p.first << "," << p.second << "],";
}
CHECK(os.str() == "[./a,0],[./d1,0],[./d1/d2,1],[./e,0],");
}
{
TemporaryDirectory t(TempOpt::change_path);
generateFile("a");
fs::create_directory("d1");
fs::create_directory("d1/d2");
generateFile("d1/d2/b");
generateFile("e");
auto iter = fs::recursive_directory_iterator(".");
std::multimap<std::string, int> result;
while(iter != fs::recursive_directory_iterator()) {
result.insert(std::make_pair(iter->path().string(), iter.depth()));
if(iter->path() == "./d1/d2") {
iter.pop();
}
#else
std::cout << dit.depth() << ": " << f.path() << std::endl;
if(dit.depth()>maxDepth) {
dit.disable_recursion_pending();
else {
++iter;
}
#endif
}
std::stringstream os;
for(auto p : result) {
os << "[" << p.first << "," << p.second << "],";
}
CHECK(os.str() == "[./a,0],[./d1,0],[./d1/d2,1],[./e,0],");
}
*/
}

TEST_CASE("30.10.15.1 absolute", "[filesystem][operations][fs.op.absolute]")
Expand Down

0 comments on commit 5ea3348

Please sign in to comment.