diff --git a/README.md b/README.md index 688a381..44dd969 100644 --- a/README.md +++ b/README.md @@ -669,6 +669,8 @@ to the expected behavior. `last_write_time()` now consistently follows symlinks. * Fix for [#208](https://github.com/gulrak/filesystem/issues/208), filesystem metadata now preserves subsecond modification times. +* Fix for [#178](https://github.com/gulrak/filesystem/issues/178), recursive + iteration no longer resolves symlinks unless requested. * Fix for [#185](https://github.com/gulrak/filesystem/issues/185), `lexically_normal()` now preserves unresolved parent components in relative paths. diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index eb01524..b47e40d 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -6047,12 +6047,13 @@ GHC_INLINE recursive_directory_iterator& recursive_directory_iterator::operator+ GHC_INLINE recursive_directory_iterator& recursive_directory_iterator::increment(std::error_code& ec) noexcept { bool isSymLink = (*this)->is_symlink(ec); - bool isDir = !ec && (*this)->is_directory(ec); + const bool followSymlink = (options() & directory_options::follow_directory_symlink) != directory_options::none; + bool isDir = !ec && (!isSymLink || followSymlink) && (*this)->is_directory(ec); if (isSymLink && detail::is_not_found_error(ec)) { ec.clear(); } if (!ec) { - if (recursion_pending() && isDir && (!isSymLink || (options() & directory_options::follow_directory_symlink) != directory_options::none)) { + if (recursion_pending() && isDir) { _impl->_dir_iter_stack.push(directory_iterator((*this)->path(), _impl->_options, ec)); } else { diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 9c89277..f72ec94 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -1681,6 +1681,21 @@ TEST_CASE("fs.class.rec.dir.itr - class recursive_directory_iterator", "[filesys } CHECK(os.str() == "d2/b,d2/ds1,d2/ds2,"); } + if (is_symlink_creation_supported()) { + TemporaryDirectory t(TempOpt::change_path); + generateFile("regular"); + fs::create_symlink("self", "self"); + std::multiset result; + REQUIRE_NOTHROW([&]() { + for (const auto& de : fs::recursive_directory_iterator(".")) { + result.insert(de.path().generic_string()); + } + }()); + CHECK(result.size() == 2); + CHECK(result.count("./regular") == 1); + CHECK(result.count("./self") == 1); + CHECK(fs::remove("self")); + } } TEST_CASE("fs.op.absolute - absolute", "[filesystem][operations][fs.op.absolute]")