mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 20:16:05 +00:00

3 error_code related cleanups/corrections in the std::filesystem operations functions. 1. In `__copy`, the `ec->clear()` is unnecessary as `ErrorHandler` at the start of each function clears the error_code as part of its initialization. 2. In `__copy`, in the recursive codepath we are not checking the error_code result of `it.increment(m_ec2)` immediately after use in the for loop condition (and we aren't checking it after the final increment when we don't enter the loop). 3. In `__weakly_canonical`, it makes calls to `__canonical` (which internally uses OS APIs implementing POSIX `realpath`) and we are not checking the error code result from the `__canonical` call. Both `weakly_canonical` and `canonical` are supposed to set the error_code when underlying OS APIs result in an error (https://eel.is/c++draft/fs.err.report#3.1). With this change we propagate up the error_code from `__canonical` caused by any underlying OS API failure up to the `__weakly_canonical`. Essentially, if `__canonical` thinks an error code should be set, then `__weakly_canonical` must as well. Before this change it would be throwing an exception in the non-error_code form of the function when `__canonical` fails, while not setting the error code in the error_code form of the function (an inconsistency). Added a little coverage in weakly_canonical.pass.cpp for the error_code forms of the API that was missing. Though I am lacking utilities in libcxx testing to add granular testing of the failure scenarios (like forcing realpath to fail for a given path, as it could if you had something like a flaky remote filesystem).