Title
What should create_directories do when p already exists but is not a directory?
Status
c++20
Section
[fs.op.create.directories][fs.op.create.directory]
Submitter
Billy Robert O'Neal III

Created on 2017-02-15.00:00:00 last changed 45 months ago

Messages

Date: 2017-07-15.23:15:19

Proposed resolution:

This wording is relative to N4640.

  1. Make the following edits to [fs.op.create_directories]:

    bool create_directories(const path& p);
    bool create_directories(const path& p, error_code& ec) noexcept;
    

    -1- Effects: Establishes the postcondition by calling Calls create_directory() for anyeach element of p that does not exist.

    -2- Postconditions: is_directory(p).

    -3- Returns: true if a new directory was created for the directory p resolves to, otherwise false. The signature with argument ec returns false if an error occurs.

    -4- Throws: As specified in [fs.err.report].

    -5- Complexity: 𝒪(n) where n is the number of elements of p that do not exist.

  2. Make the following edits to [fs.op.create_directory]:

    bool create_directory(const path& p);
    bool create_directory(const path& p, error_code& ec) noexcept;
    

    -1- Effects: Establishes the postcondition by attempting to createCreates the directory p resolves to, as if by POSIX mkdir() with a second argument of static_cast<int>(perms::all). Creation failure because p resolves to an existing directory shall not be treated asalready exists is not an error.

    -2- Postconditions: is_directory(p).

    -3- Returns: true if a new directory was created, otherwise false. The signature with argument ec returns false if an error occurs.

    -4- Throws: As specified in [fs.err.report].

Date: 2017-07-15.23:15:19

[ 2017-07 Toronto Thurs Issue Prioritization ]

Priority 0; move to Ready

Date: 2017-07-05.22:06:17

The create_directory and create_directories functions have a postcondition that says is_directory(p), but it is unclear how they are supposed to provide this. Both of their effects say that they create a directory and return whether it was actually created. It is possible to interpret this as "if creation fails due to the path already existing, issue another system call to see if the path is a directory, and change the result if so" — but it seems unfortunate to require both Windows and POSIX to issue more system calls in this case.

In email discussion Davis Herring and Billy O'Neal discussed this issue and agreed that this was probably unintentional. Special thanks for Jonathan Wakely's suggested change to create_directories' Returns clause.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2017-11-13 19:01:36adminsetstatus: voting -> wp
2017-10-17 18:34:55adminsetstatus: ready -> voting
2017-07-15 23:15:19adminsetmessages: + msg9399
2017-07-15 23:15:19adminsetstatus: new -> ready
2017-02-22 17:23:06adminsetmessages: + msg8974
2017-02-15 00:00:00admincreate