$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r78721 - in trunk/libs/filesystem: doc src test
From: bdawes_at_[hidden]
Date: 2012-05-28 11:48:00
Author: bemandawes
Date: 2012-05-28 11:47:59 EDT (Mon, 28 May 2012)
New Revision: 78721
URL: http://svn.boost.org/trac/boost/changeset/78721
Log:
Filesystem: fix #6932, create_directories throws exception even if error_code is specified.
Text files modified: 
   trunk/libs/filesystem/doc/release_history.html  |     6 ++++--                                  
   trunk/libs/filesystem/src/operations.cpp        |    36 ++++++++++++++++++++++++++++--------    
   trunk/libs/filesystem/test/convenience_test.cpp |     3 +--                                     
   trunk/libs/filesystem/test/operations_test.cpp  |     7 +++++++                                 
   4 files changed, 40 insertions(+), 12 deletions(-)
Modified: trunk/libs/filesystem/doc/release_history.html
==============================================================================
--- trunk/libs/filesystem/doc/release_history.html	(original)
+++ trunk/libs/filesystem/doc/release_history.html	2012-05-28 11:47:59 EDT (Mon, 28 May 2012)
@@ -74,9 +74,11 @@
   Implementation of filesystem::rename() method for MS Windows is wrong, by 
   adding MOVEFILE_COPY_ALLOWED to deal with renames across drives, volumes, file 
   systems. Fix has no effect on non-Windows systems.</li>
-  <li>Fix #6819; A path operand with a source that was a one character array was 
+  <li>Fix #6819, A path operand with a source that was a one character array was 
   treated as empty, even if it wasn't empty. Such arrays can occur in unions or 
   in code using C variable length array idioms.</li>
+  <li>Fix #6932, 
+  create_directories throws exception even if error_code is specified.</li>
 </ul>
 
 <h2>1.49.0</h2>
@@ -161,7 +163,7 @@
 </ul>
 <hr>
 <p>Revised
-<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->22 April, 2012<!--webbot bot="Timestamp" endspan i-checksum="29858" --></p>
+<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->28 May, 2012<!--webbot bot="Timestamp" endspan i-checksum="13984" --></p>
 <p>© Copyright Beman Dawes, 2011</p>
 <p> Use, modification, and distribution are subject to the Boost Software 
 License, Version 1.0. See <a href="http://www.boost.org/LICENSE_1_0.txt">
Modified: trunk/libs/filesystem/src/operations.cpp
==============================================================================
--- trunk/libs/filesystem/src/operations.cpp	(original)
+++ trunk/libs/filesystem/src/operations.cpp	2012-05-28 11:47:59 EDT (Mon, 28 May 2012)
@@ -916,24 +916,42 @@
   BOOST_FILESYSTEM_DECL
   bool create_directories(const path& p, system::error_code* ec)
   {
-    if (p.empty() || exists(p))
+    if (exists(p))
     {
-      if (!p.empty() && !is_directory(p))
+      if (!is_directory(p))
       {
         if (ec == 0)
-        BOOST_FILESYSTEM_THROW(filesystem_error(
+          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
+          ec->assign(system::errc::file_exists, system::generic_category());
       }
+      else if (ec)
+        ec->clear();
       return false;
     }
 
     // First create branch, by calling ourself recursively
-    create_directories(p.parent_path(), ec);
+    path parent = p.parent_path();
+    if (!parent.empty())
+    {
+      error_code local_ec;
+      create_directories(parent, local_ec);
+      if (local_ec)
+      {
+        if (ec == 0)
+          BOOST_FILESYSTEM_THROW(filesystem_error(
+            "boost::filesystem::create_directories", p, local_ec));
+        else
+          *ec = local_ec;
+        return false;
+      }
+    }
+
     // Now that parent's path exists, create the directory
     create_directory(p, ec);
-    return true;
+    return ec == 0 || *ec == 0;
   }
 
   BOOST_FILESYSTEM_DECL
@@ -941,7 +959,8 @@
   {
     if (BOOST_CREATE_DIRECTORY(p.c_str()))
     {
-      if (ec != 0) ec->clear();
+      if (ec != 0)
+        ec->clear();
       return true;
     }
 
@@ -950,7 +969,8 @@
     error_code dummy;
     if (errval == BOOST_ERROR_ALREADY_EXISTS && is_directory(p, dummy))
     {
-      if (ec != 0) ec->clear();
+      if (ec != 0)
+        ec->clear();
       return false;
     }
 
Modified: trunk/libs/filesystem/test/convenience_test.cpp
==============================================================================
--- trunk/libs/filesystem/test/convenience_test.cpp	(original)
+++ trunk/libs/filesystem/test/convenience_test.cpp	2012-05-28 11:47:59 EDT (Mon, 28 May 2012)
@@ -68,8 +68,7 @@
 
 //  create_directories() tests  --------------------------------------------------------//
 
-  BOOST_TEST(!fs::create_directories(""));  // should be harmless
-  BOOST_TEST(!fs::create_directories("/")); // ditto
+  BOOST_TEST(!fs::create_directories("/")); // should be harmless
 
   path unique_dir = fs::unique_path();  // unique name in case tests running in parallel
   path unique_yy = unique_dir / "yy";
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-28 11:47:59 EDT (Mon, 28 May 2012)
@@ -1079,6 +1079,13 @@
     BOOST_TEST(fs::create_directories(p));
     BOOST_TEST(fs::exists(p));
     BOOST_TEST(fs::is_directory(p));
+
+    if (fs::exists("/permissions_test"))
+    {
+      error_code ec;
+      BOOST_TEST(!fs::create_directories("/permissions_test/another_directory", ec));
+      BOOST_TEST(ec);
+    }
   }
 
   //  resize_file_tests  ---------------------------------------------------------------//