Skip to content
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

create_directories should return false when the path already exists #55

Closed
Alzathar opened this issue Mar 5, 2020 · 2 comments
Closed
Assignees
Labels
available on master Fix is done on master branch, issue closed on next release bug Something isn't working
Milestone

Comments

@Alzathar
Copy link

Alzathar commented Mar 5, 2020

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;
//...
@gulrak gulrak self-assigned this Mar 5, 2020
@gulrak gulrak added the bug Something isn't working label Mar 5, 2020
@gulrak
Copy link
Owner

gulrak commented Mar 5, 2020

Thank you, another missing test case found.

gulrak added a commit that referenced this issue Mar 5, 2020
@gulrak gulrak added the available on master Fix is done on master branch, issue closed on next release label Mar 5, 2020
@Alzathar
Copy link
Author

Alzathar commented Mar 5, 2020

This fixes the issue. Thank you very much!

@Alzathar Alzathar closed this as completed Mar 5, 2020
@gulrak gulrak added this to the v1.3.1 milestone Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
available on master Fix is done on master branch, issue closed on next release bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants