Propagate weakly_canonical() component lookup errors and improve error handling in filesystem tests (#204)

This commit is contained in:
Steffen Schümann 2026-07-11 21:48:57 +02:00
parent 6dfddd981e
commit 48a868a11a
3 changed files with 14 additions and 2 deletions

View File

@ -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.

View File

@ -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 {

View File

@ -2862,6 +2862,17 @@ 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');
CHECK(fs::weakly_canonical(invalid, ec).empty());
CHECK(ec);
#ifdef GHC_WITH_EXCEPTIONS
CHECK_THROWS_AS(fs::weakly_canonical(invalid), fs::filesystem_error);
#endif
}
}