Issue 2935: What should create_directories do when p already exists but is not a directory? (original) (raw)
This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++20 status.
2935. What should create_directories do when p already exists but is not a directory?
Section: 31.12.13.7 [fs.op.create.directories], 31.12.13.8 [fs.op.create.directory] Status: C++20 Submitter: Billy Robert O'Neal III Opened: 2017-02-15 Last modified: 2021-06-06
Priority: 0
View all issues with C++20 status.
Discussion:
The create_directory and create_directories functions have a postcondition that saysis_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.
[2017-07 Toronto Thurs Issue Prioritization]
Priority 0; move to Ready
Proposed resolution:
This wording is relative to N4640.
- 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 callingCallscreate_directory()foranyeach element ofpthat does not exist.-2- Postconditions:is_directory(p).
-3- Returns:trueif a new directory was created for the directorypresolves to, otherwisefalse. The signature with argumentecreturnsfalseif an error occurs.
-4- Throws: As specified in 31.12.5 [fs.err.report].
-5- Complexity: 𝒪(n) where n is the number of elements ofpthat do not exist. - 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 directorypresolves to, as if by POSIXmkdir()with a second argument ofstatic_cast<int>(perms::all). Creation failure becausepresolves to an existing directory shall not be treated asalready exists is not an error.-2- Postconditions:is_directory(p).
-3- Returns:trueif a new directory was created, otherwisefalse. The signature with argumentecreturnsfalseif an error occurs.
-4- Throws: As specified in 31.12.5 [fs.err.report].