<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2935: What should create_directories do when p already exists but is not a directory?</title>
<meta property="og:title" content="Issue 2935: What should create_directories do when p already exists but is not a directory?">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2935.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++20">C++20</a> status.</em></p>
<h3 id="2935"><a href="lwg-defects.html#2935">2935</a>. What should <code>create_directories</code> do when <code>p</code> already exists but is not a directory?</h3>
<p><b>Section:</b> 31.12.13.7 <a href="https://wg21.link/fs.op.create.directories">[fs.op.create.directories]</a>, 31.12.13.8 <a href="https://wg21.link/fs.op.create.directory">[fs.op.create.directory]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Billy Robert O'Neal III <b>Opened:</b> 2017-02-15 <b>Last modified:</b> 2021-06-06</p>
<p><b>Priority: </b>0
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The <code>create_directory</code> and <code>create_directories</code> functions have a postcondition that says
<code>is_directory(p)</code>, 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" &mdash; but it seems unfortunate to require both Windows and POSIX to issue more
system calls in this case.
<p/>
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 <code>create_directories</code>'
<em>Returns</em> clause.
</p>

<p><i>[2017-07 Toronto Thurs Issue Prioritization]</i></p>

<p>Priority 0; move to Ready</p>


<p id="res-2935"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4640">N4640</a>.</p>

<ol>
<li><p>Make the following edits to  [fs.op.create_directories]:</p>

<blockquote>
<pre>
bool create_directories(const path&amp; p);
bool create_directories(const path&amp; p, error_code&amp; ec) noexcept;
</pre>
</blockquote>
<p>
-1- <em>Effects:</em><del> Establishes the postcondition by calling </del><ins>Calls </ins><code>create_directory()</code> for <del>any</del><ins>each</ins> element of <code>p</code> that does not exist.
<p/>
<del>-2- <em>Postconditions:</em> <code>is_directory(p)</code>.</del>
<p/>
-3- <em>Returns:</em> <code>true</code> if a new directory was created <ins>for the directory <code>p</code> resolves to</ins>,
otherwise <code>false</code>. The signature with argument <code>ec</code> returns <code>false</code> if an error occurs.
<p/>
-4- <em>Throws:</em> As specified in 31.12.5 <a href="https://wg21.link/fs.err.report">[fs.err.report]</a>.</p>
<p>
-5- <em>Complexity:</em> &#x1d4aa;(<i>n</i>) where <i>n</i> is the number of elements of <code>p</code><del> that do not exist</del>.
</p>
</li>

<li><p>Make the following edits to  [fs.op.create_directory]:</p>

<blockquote>
<pre>
bool create_directory(const path&amp; p);
bool create_directory(const path&amp; p, error_code&amp; ec) noexcept;
</pre>
</blockquote>
<p>
-1- <em>Effects:</em><del> Establishes the postcondition by attempting to create</del><ins>Creates</ins> the directory
<code>p</code> resolves to, as if by POSIX <code>mkdir()</code> with a second argument of <code>static_cast&lt;int&gt;(perms::all)</code>.
Creation failure because <code>p</code> <del>resolves to an existing directory shall not be treated as</del><ins>already exists
is not</ins> an error.
<p/>
<del>-2- <em>Postconditions:</em> <code>is_directory(p)</code>.</del>
<p/>
-3- <em>Returns:</em> <code>true</code> if a new directory was created, otherwise <code>false</code>. The signature with argument
<code>ec</code> returns <code>false</code> if an error occurs.
<p/>
-4- <em>Throws:</em> As specified in 31.12.5 <a href="https://wg21.link/fs.err.report">[fs.err.report]</a>.
</p>
</li>
</ol>






</body>
</html>
