That's a follow-up patch after D92769.
Details
- Reviewers
ldionne mstorsjo - Group Reviewers
Restricted Project - Commits
- rG59c72a701215: [libc++] [P1164] Add tests for create_directories. NFC.
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Regarding https://reviews.llvm.org/D92769#inline-868480. @mstorsjo
If parent does exist, but isn't a directory, the check if (not exists(parent_st)) above won't trigger, so it won't hit the case of calling __create_directory("parent_which_is_file"), but will instead call __create_directory("parent_which_is_file/subdir"). That call doesn't return the error code corresponding to EEXIST, but gives an error corresponding to no_such_file_or_directory/ENOENT instead.
By extending the check above into if (not exists(parent_st)) { ... } else if (!is_directory(parent)) return err.report(errc::file_exists);, one would get the more expected error code here too.
MS STL has indeed a special handling of errors while creating directories. See https://github.com/microsoft/STL/blob/68b344c9dcda6ddf1a8fca112cb9033f9e50e787/stl/inc/filesystem#L3766-L3777
I think we can do something similar indeed, so that the error that pops up is the error the one would expect.
I'll take a look at the tests they do and try to improve handling in libc++.
libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp | ||
---|---|---|
106 | Btw, the filesystem tests has got a helper function, that would allow writing this as ErrorIs(ec, std::errc::file_exists) - but I verified that this form also seems to work. The thing is, that with MS STL, the returned error codes don't use the standard std::errc values and category, but wrap the windows native error codes. The ErrorIs() helper explicitly converts them to the generic error category (via ec.default_error_condition()) before comparing error values, but it looks like operator==() does the same as well, implicitly. |
libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp | ||
---|---|---|
106 | Ok, I use ErrorIs now, even it doesn't change much. But it may be future proof. |
libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp | ||
---|---|---|
106 | Not in libc++ itself, but MS STL produces such error codes (and I have a setup where I run the libc++ tests against MS STL). |
Btw, the filesystem tests has got a helper function, that would allow writing this as ErrorIs(ec, std::errc::file_exists) - but I verified that this form also seems to work.
The thing is, that with MS STL, the returned error codes don't use the standard std::errc values and category, but wrap the windows native error codes. The ErrorIs() helper explicitly converts them to the generic error category (via ec.default_error_condition()) before comparing error values, but it looks like operator==() does the same as well, implicitly.