Fix filesystem's handling of nonexistent network paths emitting ERROR_INVALID_NAME #800
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On my machine,
P0218R1_filesystem
was failing whenever it tested nonexistent network paths. (I'm not sure why nobody else has observed this yet; I'm just running a normal Microsoft corpnet installation of Windows 10 Enterprise.)I debugged into this, and observed that when
__std_fs_get_stats()
callsGetFileAttributesExW()
, it fails withERROR_INVALID_NAME
:STL/stl/src/filesystem.cpp
Lines 919 to 921 in 65d98ff
This is returned unchanged by
_File_size()
:STL/stl/inc/filesystem
Lines 3377 to 3388 in 65d98ff
The test expects
file_size()
to returnbad_file_size
, which it does, but it also expectsec == errc::no_such_file_or_directory
, which fails:STL/tests/std/tests/P0218R1_filesystem/test.cpp
Lines 2713 to 2716 in 65d98ff
This is because we map
ERROR_INVALID_NAME
toerrc::invalid_argument
:STL/stl/src/syserror.cpp
Line 50 in 65d98ff
The Windows documentation for System Error Codes describes
ERROR_INVALID_NAME
as "The filename, directory name, or volume label syntax is incorrect." so this is specific to filesystem operations; it isn't a general error code for invalid arguments.Additionally,
__std_is_file_not_found()
already considers__std_win_error::_Invalid_name
(our synonym forERROR_INVALID_NAME
) to be a "file not found" error code:STL/stl/inc/xfilesystem_abi.h
Lines 51 to 61 in 65d98ff
The other 3 error codes are already mapped to
errc::no_such_file_or_directory
:STL/stl/src/syserror.cpp
Line 44 in 65d98ff
STL/stl/src/syserror.cpp
Line 64 in 65d98ff
STL/stl/src/syserror.cpp
Line 27 in 65d98ff
Changing the mapping of
ERROR_INVALID_NAME
(and updating the test's direct inspection ofec.value()
) fixes this bug.This is a behavioral change (similar to #406 and #616, although they added new mappings). As this fixes the behavior of
<filesystem>
, I believe it is necessary.