-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<filesystem> Treat ERROR_BAD_NETPATH as file not found. #616
Conversation
Resolves microsoftGH-615 / DevCom-950424. * Extract _Is_file_not_found to <xfilesystem_abi.h> as __std_is_file_not_found because we also need that in filesystem.cpp. * Add ERROR_BAD_NETPATH to __std_is_file_not_found. * Map ERROR_BAD_NETPATH to errc::no_such_file_or_directory. * Change filesystem tests that look for file not exists behavior to also test bad network paths.
stl/inc/xfilesystem_abi.h
Outdated
case __std_win_error::_File_not_found: | ||
case __std_win_error::_Path_not_found: | ||
case __std_win_error::_Invalid_name: | ||
case __std_win_error::_Error_bad_netpath: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are neither lexicographically sorted nor enumerator sorted.
@@ -25,6 +25,7 @@ static constexpr _Win_errtab_t _Win_errtab[] = { | |||
{ERROR_ACCESS_DENIED, errc::permission_denied}, | |||
{ERROR_ALREADY_EXISTS, errc::file_exists}, | |||
{ERROR_BAD_UNIT, errc::no_such_device}, | |||
{ERROR_BAD_NETPATH, errc::no_such_file_or_directory}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be lexicographically sorted.
switch (_Err) { | ||
case __std_win_error::_File_not_found: | ||
case __std_win_error::_Path_not_found: | ||
if (__std_is_file_not_found(_Err)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this is additionally translating __std_win_error::_Invalid_name
. That seems desirable, but is it possible to construct a test case for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know of one. Every bogus path I was able to form is coming back with the netpath one :(. I observe the _Invalid_name one was added in https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_git/msvc/commit/4110cc61e2e22dc826c2ba517a237dc76134ab63 -- it might have just been emailed to me or something that someone saw it somewhere.
Even without test cases I don't think there's good reason for variation on what we consider not found.
constexpr wstring_view badPath = L"// ?? ?? ///// ?? ?? ? ////"sv; | ||
constexpr wstring_view nonexistentPath = L"C:/This/Path/Should/Not/Exist"sv; | ||
constexpr wstring_view badPath = L"// ?? ?? ///// ?? ?? ? ////"sv; | ||
path nonexistentPaths[] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this global array modifiable? Could it instead be constexpr wstring_view[]
with path
constructed later on demand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be but then it's awkward to use / debug through because you step through path / wstring constructors constantly. I could make it const but it isn't used for anything constexpr here.
EXPECT(status(nonexistent).type() == file_type::not_found); // should not throw | ||
EXPECT(status(nonexistent, ec).type() == file_type::not_found); | ||
EXPECT(ec.category() == system_category()); | ||
EXPECT(ec.value() == 2 || ec.value() == 3 || ec.value() == 53); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-existing, but bigger now: should there be a comment as to what these magic values mean?
} | ||
|
||
// test VSO-654638 where create_directory(p, existing_p) was doing copy_symlink behavior | ||
{ | ||
error_code ec; | ||
create_directory_symlink(nonexistentPath, p, ec); | ||
create_directory_symlink(nonexistentPaths[0], p, ec); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it critical that nonexistentPaths[0]
be a local nonexistent path? If so, should that be commented above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it just needed to be any nonexistent path. Do you want a separate variable like "anyGivenNonexistentPath"? (I want to avoid reusing nonexistentPath
when there's already a variable nonexistentPaths
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think it's fine.
Resolves GH-615 / DevCom-950424.
Checklist
Be sure you've read README.md and understand the scope of this repo.
If you're unsure about a box, leave it unchecked. A maintainer will help you.
_Ugly
as perhttps://eel.is/c++draft/lex.name#3.1 or there are no product code changes.
verified by an STL maintainer before automated testing is enabled on GitHub,
leave this unchecked for initial submission).
members, adding virtual functions, changing whether a type is an aggregate
or trivially copyable, etc.).
the C++ Working Draft (including any cited standards), other WG21 papers
(excluding reference implementations outside of proposed standard wording),
and LWG issues as reference material. If they were derived from a project
that's already listed in NOTICE.txt, that's fine, but please mention it.
If they were derived from any other project (including Boost and libc++,
which are not yet listed in NOTICE.txt), you must mention it here,
so we can determine whether the license is compatible and what else needs
to be done.