This is an archive of the discontinued LLVM Phabricator instance.

[libc++] [P1164] Add tests for create_directories. NFC.
ClosedPublic

Authored by curdeius on Dec 10 2020, 4:56 AM.

Details

Summary

That's a follow-up patch after D92769.

Diff Detail

Event Timeline

curdeius requested review of this revision.Dec 10 2020, 4:56 AM
curdeius created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 10 2020, 4:56 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

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

curdeius updated this revision to Diff 311533.Dec 14 2020, 2:44 AM
  • Check exact error codes.
mstorsjo added inline comments.Dec 14 2020, 3:04 AM
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.

curdeius updated this revision to Diff 311550.Dec 14 2020, 4:25 AM
  • Mark macosx10.15 as XFAIL.
  • Use ErrorIs.
curdeius marked an inline comment as done.Dec 14 2020, 4:28 AM
curdeius added inline comments.
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.
Do you have a scenario where the returned error code would be unintuitive?

mstorsjo added inline comments.Dec 14 2020, 4:32 AM
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).

ldionne accepted this revision.Dec 14 2020, 7:52 AM
This revision is now accepted and ready to land.Dec 14 2020, 7:52 AM
This revision was automatically updated to reflect the committed changes.
curdeius marked an inline comment as done.