[Bug libstdc++/101510] std::filesystem::create_directory on an existing symlink to a directory
enometh at meer dot net
gcc-bugzilla@gcc.gnu.org
Tue Jul 20 15:55:27 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101510
--- Comment #5 from Madhu <enometh at meer dot net> ---
* "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
<bug-101510-34102-sqMEQj9IHu@http.gcc.gnu.org/bugzilla/>
Wrote on Tue, 20 Jul 2021 11:46:32 +0000
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101510
>
> --- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> (In reply to Madhu from comment #0)
>> cppreference.com states
>>
>> ```
>> bool create_directory( const std::filesystem::path& p );
>>
>> Creates the directory p as if by POSIX mkdir() with a second argument of
>> static_cast<int>(std::filesystem::perms::all) (the parent directory must
>> already exist). If the function fails because p resolves to an existing
>> directory, no error is reported. Otherwise on failure an error is reported.
>> ```
>>
>> This should accomodate situations when `p' resolves to an existing directory
>> when `p' it is a symbolic link.
>>
>> However create_directory(p) fails when p is a symbolic link which points
>> to an existing directory.
>>
>> The standard usage pattern is to call mkdir(p) - and if it fails on EEXIST
>> to stat(2) p - following symlinks, and check if is a directory. The pattern
>> is used to ensure that `p' can be treated as a directory for further
>> operations and this includes p being a symbolic link to a directory)
>
> You can do this with create_directory. If create_directory(p) doesn't throw an
> exception, then is_directory(p) is true. Or without exceptions:
>
> std::error_code ec;
> create_directory(p, ec);
> if (!ec)
> {
> // p resolves to a directory
> }
>
It looks like I did indeed get the semantics wrong
I was going by the usage from databasePath() in
https://github.com/WebKit/WebKit/blob/main/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabaseTracker.cpp#L142
which calls ensureDatabaseDirectoryExists() in
https://github.com/WebKit/WebKit/blob/main/Source/WebCore/platform/sql/SQLiteFileSystem.cpp#L59
which calls makeAllDirectories()
https://github.com/WebKit/WebKit/blob/main/Source/WTF/wtf/FileSystem.cpp#L733
The check is for only on the boolean value of ec, which is wrong
according to the spec, Thanks!
Instead of precipitately filing the bug here I should have filed it
with WebKit.
More information about the Gcc-bugs
mailing list