create_directories should return false when the path already exists #55
Closed
Description
Describe the bug
For the methods filesystem::create_directories
, the document N4687 says (see 30.10.15.6)
Returns: true if a new directory was created, otherwise false. The signature with argument ec returns false if an error occurs.
However, the current implementation in v1.3.0 returns true everytime.
To Reproduce
// should return false as the folder already exists
std::cout << boolalpha << std::filesystem::create_directories(std::filesystem::current_path()) << std::endl
Expected behavior
In case the path already exists and this is a directory, the returned value should be false
. This is the behaviour implemented within VS2019 (16.4) and Xcode 11.
Additional context
A way to fix this issue could be to test if the path already exists. For example
// Around line 3400
GHC_INLINE bool create_directories(const path& p, std::error_code& ec) noexcept
{
path current;
ec.clear();
// BEGIN_PROPOSITION
std::error_code tec;
auto fs = status(p, tec);
if (status_known(fs) && exists(fs) && is_directory(fs)) {
return false;
}
// END_PROPOSITION
for (path::string_type part : p) {
current /= part;
//...