Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78747 - in trunk/libs/filesystem: doc doc/src src test
From: bdawes_at_[hidden]
Date: 2012-05-29 11:53:03


Author: bemandawes
Date: 2012-05-29 11:53:02 EDT (Tue, 29 May 2012)
New Revision: 78747
URL: http://svn.boost.org/trac/boost/changeset/78747

Log:
Filesystem: Further fixes for #6932. Clarify docs. Add test cases.
Text files modified:
   trunk/libs/filesystem/doc/reference.html | 25 ++++++++++++--------
   trunk/libs/filesystem/doc/src/source.html | 25 ++++++++++++--------
   trunk/libs/filesystem/doc/src/tr2_snippets.html | 17 +++++++++++++
   trunk/libs/filesystem/src/operations.cpp | 48 +++++++++++++++++++--------------------
   trunk/libs/filesystem/test/operations_test.cpp | 12 ++++++---
   5 files changed, 77 insertions(+), 50 deletions(-)

Modified: trunk/libs/filesystem/doc/reference.html
==============================================================================
--- trunk/libs/filesystem/doc/reference.html (original)
+++ trunk/libs/filesystem/doc/reference.html 2012-05-29 11:53:02 EDT (Tue, 29 May 2012)
@@ -2287,18 +2287,24 @@
 <pre>bool <a name="create_directories">create_directories</a>(const path&amp; p);
 bool <a name="create_directories2">create_directories</a>(const path&amp; p, system::error_code&amp; ec);</pre>
 <blockquote>
- <p><i>Requires:</i> <code>p.empty() || <br>
- forall px: px == p || is_parent(px, p): is_directory(px) || !exists( px )</code> </p>
+ <p><i>Effects:</i> Establishes the postcondition by calling <code>
+ create_directory()</code> for any element of <code>p</code> that does not
+ exist.</p>
   <p><i>Postcondition:</i> <code>is_directory(p)</code></p>
- <p><i>Returns:</i> The value of <code>!exists(p)</code> prior to the
- establishment of the postcondition.</p>
+ <p><i>Returns:</i> <code>true</code> if a new directory was created, otherwise <code>
+ false</code>.</p>
   <p><i>Throws:</i> As specified in Error reporting.</p>
+ <p><i>Complexity:</i> <i>O(n+1)</i> where <i>n</i> is the number of elements
+ of <code>p</code> that do not exist.</p>
 </blockquote>
 <pre>bool <a name="create_directory">create_directory</a>(const path&amp; p);
 bool <a name="create_directory2">create_directory</a>(const path&amp; p, system::error_code&amp; ec);</pre>
 <blockquote>
- <p><i>Effects:</i> Attempts to create the directory <code>p</code> resolves to,
- as if by<i> POSIX </i><code>mkdir()</code> with a second argument of S_IRWXU|S_IRWXG|S_IRWXO. </p>
+ <p><i>Effects:</i> Establishes the postcondition by attempting to create the
+ directory <code>p</code> resolves to, as if by<i> POSIX </i><code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/mkdir.html">
+ mkdir()</a></code> with a second argument of S_IRWXU|S_IRWXG|S_IRWXO. Creation
+ failure because <code>p</code> resolves to an existing directory shall not be
+ treated as an error. </p>
   <p><i>Postcondition:</i> <code>is_directory(p)</code></p>
   <p><i>Returns:</i> <code>true</code> if a new directory was created, otherwise <code>false</code>.</p>
   <p><i>Throws:</i> As specified in Error reporting.</p>
@@ -2383,10 +2389,9 @@
 <pre>bool <a name="exists2">exists</a>(const path&amp; p);
 bool <a name="exists3">exists</a>(const path&amp; p, system::error_code&amp; ec) noexcept;</pre>
 <blockquote>
- <p><i>Returns:</i> <code>exists(status(p))</code> or <code>exists(status(p, ec))</code>,
- respectively.</p>
-<p><i>Throws:</i> <code>filesystem_error</code>; overload with <code>error_code&amp;</code> throws
-nothing.</p>
+ <p dir="ltr"><i>Returns:</i> <code>exists(status(p))</code> or <code>exists(status(p, ec))</code>,
+ respectively. If ec != 0 and an error</p>
+<p><i>Throws:</i> As specified in Error reporting.</p>
 </blockquote>
 <pre><code>bool <a name="equivalent">equivalent</a>(const path&amp; p1, const path&amp; p2);
 bool <a name="equivalent2">equivalent</a>(const path&amp; p1, const path&amp; p2, system::error_code&amp; ec);</code></pre>

Modified: trunk/libs/filesystem/doc/src/source.html
==============================================================================
--- trunk/libs/filesystem/doc/src/source.html (original)
+++ trunk/libs/filesystem/doc/src/source.html 2012-05-29 11:53:02 EDT (Tue, 29 May 2012)
@@ -2227,18 +2227,24 @@
 <pre>bool <a name="create_directories">create_directories</a>(const path&amp; p);
 bool <a name="create_directories2">create_directories</a>(const path&amp; p, system::error_code&amp; ec);</pre>
 <blockquote>
- <p><i>Requires:</i> <code>p.empty() || <br>
- forall px: px == p || is_parent(px, p): is_directory(px) || !exists( px )</code> </p>
+ <p><i>Effects:</i> Establishes the postcondition by calling <code>
+ create_directory()</code> for any element of <code>p</code> that does not
+ exist.</p>
   <p><i>Postcondition:</i> <code>is_directory(p)</code></p>
- <p><i>Returns:</i> The value of <code>!exists(p)</code> prior to the
- establishment of the postcondition.</p>
+ <p><i>Returns:</i> <code>true</code> if a new directory was created, otherwise <code>
+ false</code>.</p>
   <p><i>Throws:</i> As specified in Error reporting.</p>
+ <p><i>Complexity:</i> <i>O(n+1)</i> where <i>n</i> is the number of elements
+ of <code>p</code> that do not exist.</p>
 </blockquote>
 <pre>bool <a name="create_directory">create_directory</a>(const path&amp; p);
 bool <a name="create_directory2">create_directory</a>(const path&amp; p, system::error_code&amp; ec);</pre>
 <blockquote>
- <p><i>Effects:</i> Attempts to create the directory <code>p</code> resolves to,
- as if by<i> POSIX </i><code>mkdir()</code> with a second argument of S_IRWXU|S_IRWXG|S_IRWXO. </p>
+ <p><i>Effects:</i> Establishes the postcondition by attempting to create the
+ directory <code>p</code> resolves to, as if by<i> POSIX </i><code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/mkdir.html">
+ mkdir()</a></code> with a second argument of S_IRWXU|S_IRWXG|S_IRWXO. Creation
+ failure because <code>p</code> resolves to an existing directory shall not be
+ treated as an error. </p>
   <p><i>Postcondition:</i> <code>is_directory(p)</code></p>
   <p><i>Returns:</i> <code>true</code> if a new directory was created, otherwise <code>false</code>.</p>
   <p><i>Throws:</i> As specified in Error reporting.</p>
@@ -2323,10 +2329,9 @@
 <pre>bool <a name="exists2">exists</a>(const path&amp; p);
 bool <a name="exists3">exists</a>(const path&amp; p, system::error_code&amp; ec) noexcept;</pre>
 <blockquote>
- <p><i>Returns:</i> <code>exists(status(p))</code> or <code>exists(status(p, ec))</code>,
- respectively.</p>
-<p><i>Throws:</i> <code>filesystem_error</code>; overload with <code>error_code&amp;</code> throws
-nothing.</p>
+ <p dir="ltr"><i>Returns:</i> <code>exists(status(p))</code> or <code>exists(status(p, ec))</code>,
+ respectively. If ec != 0 and an error</p>
+<p><i>Throws:</i> As specified in Error reporting.</p>
 </blockquote>
 <pre><code>bool <a name="equivalent">equivalent</a>(const path&amp; p1, const path&amp; p2);
 bool <a name="equivalent2">equivalent</a>(const path&amp; p1, const path&amp; p2, system::error_code&amp; ec);</code></pre>

Modified: trunk/libs/filesystem/doc/src/tr2_snippets.html
==============================================================================
--- trunk/libs/filesystem/doc/src/tr2_snippets.html (original)
+++ trunk/libs/filesystem/doc/src/tr2_snippets.html 2012-05-29 11:53:02 EDT (Tue, 29 May 2012)
@@ -20,7 +20,7 @@
     <tr>
       <td width="153" align="left" valign="top">Date:</td>
       <td width="426">
- <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%Y-%m-%d" startspan -->2012-04-18<!--webbot bot="Timestamp" endspan i-checksum="12247" --></td>
+ <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%Y-%m-%d" startspan -->2012-04-24<!--webbot bot="Timestamp" endspan i-checksum="12240" --></td>
     </tr>
     <tr>
       <td width="153" align="left" valign="top">Project:</td>
@@ -394,6 +394,21 @@
 quoted manipulator, that's a separate proposal for a different TR.)</i></p>
 <p><i>Action:&nbsp; Beman to apply to proposed wording.</i></p>
 <hr>
+<h3>Issue 8: Rename <code>rename</code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+Status: New</h3>
+<h4>Discussion</h4>
+<p>There are minor problems with the name of the <code>rename()</code> function:</p>
+<ul>
+ <li>There is already a &quot;rename&quot; function, albeit in namespace std, and it has
+ different semantics as regards error handling. Thus giving the function a
+ different name might reduce the chance of user error.</li>
+ <li>The name &quot;move&quot; would&nbsp; better reflect the actual semantics,
+ particularly for moves between directories., and this is the name used by some
+ API's, console commands, and GUI file managers for that functionality.</li>
+</ul>
+<h4>Proposed resolution</h4>
+<p>Change the name of the <code>rename()</code> function to <code>move()</code>.</p>
+<hr>
 <p>$endid
 
 $id backmatter=

Modified: trunk/libs/filesystem/src/operations.cpp
==============================================================================
--- trunk/libs/filesystem/src/operations.cpp (original)
+++ trunk/libs/filesystem/src/operations.cpp 2012-05-29 11:53:02 EDT (Tue, 29 May 2012)
@@ -913,45 +913,43 @@
 # endif
   }
 
- BOOST_FILESYSTEM_DECL
+ BOOST_FILESYSTEM_DECL
   bool create_directories(const path& p, system::error_code* ec)
   {
- if (exists(p))
+ error_code local_ec;
+ file_status p_status = status(p, local_ec);
+
+ if (p_status.type() == directory_file)
     {
- if (!is_directory(p))
- {
- if (ec == 0)
- BOOST_FILESYSTEM_THROW(filesystem_error(
- "boost::filesystem::create_directories", p,
- error_code(system::errc::file_exists, system::generic_category())));
- else
- ec->assign(system::errc::file_exists, system::generic_category());
- }
- else if (ec)
+ if (ec != 0)
         ec->clear();
       return false;
     }
 
- // First create branch, by calling ourself recursively
     path parent = p.parent_path();
     if (!parent.empty())
     {
- error_code local_ec;
- create_directories(parent, local_ec);
- if (local_ec)
+ // determine if the parent exists
+ file_status parent_status = status(parent, local_ec);
+
+ // if the parent does not exist, create the parent
+ if (parent_status.type() == file_not_found)
       {
- if (ec == 0)
- BOOST_FILESYSTEM_THROW(filesystem_error(
- "boost::filesystem::create_directories", p, local_ec));
- else
- *ec = local_ec;
- return false;
+ create_directories(parent, local_ec);
+ if (local_ec)
+ {
+ if (ec == 0)
+ BOOST_FILESYSTEM_THROW(filesystem_error(
+ "boost::filesystem::create_directories", parent, local_ec));
+ else
+ *ec = local_ec;
+ return false;
+ }
       }
     }
 
- // Now that parent's path exists, create the directory
- create_directory(p, ec);
- return ec == 0 || *ec == 0;
+ // create the directory
+ return create_directory(p, ec);
   }
 
   BOOST_FILESYSTEM_DECL

Modified: trunk/libs/filesystem/test/operations_test.cpp
==============================================================================
--- trunk/libs/filesystem/test/operations_test.cpp (original)
+++ trunk/libs/filesystem/test/operations_test.cpp 2012-05-29 11:53:02 EDT (Tue, 29 May 2012)
@@ -1073,7 +1073,9 @@
   {
     cout << "create_directories_tests..." << endl;
 
- fs::path p = dir / "level1" / "level2";
+ BOOST_TEST(!fs::create_directories("/"));
+
+ fs::path p = dir / "level1" / "level2" / "level3";
 
     BOOST_TEST(!fs::exists(p));
     BOOST_TEST(fs::create_directories(p));
@@ -1083,6 +1085,7 @@
     if (fs::exists("/permissions_test"))
     {
       error_code ec;
+ BOOST_TEST(!fs::create_directories("/permissions_test", ec));
       BOOST_TEST(!fs::create_directories("/permissions_test/another_directory", ec));
       BOOST_TEST(ec);
     }
@@ -1598,7 +1601,7 @@
     // Windows only tests
     if (platform == "Windows")
     {
- cout << "Window specific tests..." << endl;
+ cout << "Windows specific tests..." << endl;
       if (!skip_long_windows_tests)
       {
         cout << " (may take several seconds)"<< endl;
@@ -1939,7 +1942,6 @@
   initial_tests();
   predicate_and_status_tests();
   exception_tests();
- platform_specific_tests();
   create_directory_tests();
   current_directory_tests();
   space_tests();
@@ -1992,8 +1994,10 @@
   if (create_symlink_ok) // only if symlinks supported
     remove_symlink_tests();
   write_time_tests(dir);
-
   temp_directory_path_tests();
+
+ platform_specific_tests(); // do these last since they take a lot of time on Windows,
+ // and that's a pain during manual testing
   
   cout << "testing complete" << endl;
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk