diff --git a/README.md b/README.md index 7330593..0ec2099 100644 --- a/README.md +++ b/README.md @@ -659,6 +659,8 @@ to the expected behavior. `lexically_normal()` now preserves IPv6 components in device UNC paths. * Fix for [#171](https://github.com/gulrak/filesystem/issues/171), `canonical()` now supports device UNC paths. +* Fix for [#204](https://github.com/gulrak/filesystem/issues/204), + `weakly_canonical()` now propagates component lookup errors. * 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 58f6ba8..454dfe7 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -5150,8 +5150,7 @@ GHC_INLINE path weakly_canonical(const path& p, std::error_code& ec) noexcept bool scan = true; for (auto pe : p) { if (scan) { - std::error_code tec; - if (exists(result / pe, tec)) { + if (exists(result / pe, ec)) { result /= pe; } else { diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 6761db2..263a837 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -2862,6 +2862,24 @@ TEST_CASE("fs.op.weakly_canonical - weakly_canonical", "[filesystem][operations] CHECK(fs::weakly_canonical(rel / "d1/../f0") == dir / "f0"); CHECK(fs::weakly_canonical(rel / "d1/../f1") == dir / "f1"); CHECK(fs::weakly_canonical(rel / "d1/../f1/../f2") == dir / "f2"); + + std::error_code ec(42, std::system_category()); + CHECK(fs::weakly_canonical(dir / "missing/child", ec) == dir / "missing/child"); + CHECK(!ec); + + const auto invalid = dir / std::string(1024, 'x'); + std::error_code lookupError; + CHECK_FALSE(fs::exists(invalid, lookupError)); +#ifndef GHC_OS_WINDOWS + REQUIRE(lookupError); +#endif + if (lookupError) { + CHECK(fs::weakly_canonical(invalid, ec).empty()); + CHECK(ec == lookupError); +#ifdef GHC_WITH_EXCEPTIONS + CHECK_THROWS_AS(fs::weakly_canonical(invalid), fs::filesystem_error); +#endif + } } }