[Saga-devel] saga SVN commit 3283: /trunk/adaptors/default/file/

hkaiser at cct.lsu.edu hkaiser at cct.lsu.edu
Wed Jan 14 20:03:45 CST 2009


User: hkaiser
Date: 2009/01/14 08:03 PM

Modified:
 /trunk/adaptors/default/file/
  default_dir.cpp

Log:
 Fixed default file adaptor to properly create directory hierarchies if both flags are specified: Create|CreateParents

File Changes:

Directory: /trunk/adaptors/default/file/
========================================

File [modified]: default_dir.cpp
Delta lines: +29 -32
===================================================================
--- trunk/adaptors/default/file/default_dir.cpp	2009-01-14 21:35:15 UTC (rev 3282)
+++ trunk/adaptors/default/file/default_dir.cpp	2009-01-15 02:03:43 UTC (rev 3283)
@@ -12,6 +12,8 @@
 #include <saga/saga/url.hpp>
 #include <saga/impl/config.hpp>
 
+#include <boost/filesystem/convenience.hpp>
+
 #include "default_dir.hpp"
 #include "default_file.hpp"
 
@@ -65,35 +67,32 @@
 
     // check for openmode //
     saga::filesystem::flags OpenMode = (saga::filesystem::flags)data->mode_;
-
-    if(exists)
-    {
-        if(!is_dir)
-        {
+    if (exists) {
+        if (!is_dir) {
             SAGA_ADAPTOR_THROW ("URL does not point to a directory: " +
                                 data->location_.get_url(), saga::BadParameter);
         }
-        else
-        {
-            if((OpenMode & saga::filesystem::Create) && (OpenMode & saga::filesystem::Exclusive))
+        else {
+            if ((OpenMode & saga::filesystem::Create) && (OpenMode & saga::filesystem::Exclusive))
             {
                 SAGA_ADAPTOR_THROW ("Directory " + data->location_.get_url() +
                                     " already exists.", saga::AlreadyExists); 
             }
         }
     }
-    else // !exists
-    {
-        if(!(OpenMode & saga::filesystem::Create))
-        {
+    else {  // !exists
+        if (!(OpenMode & saga::filesystem::Create)) {
             SAGA_ADAPTOR_THROW ("Directory does not exist and saga::filesystem::Create flag not given: " +
                                 data->location_.get_url(), saga::DoesNotExist);
         }
-        else
-        {
+        else {
             try {
-                if (!fs::create_directory (path)) {
+                if ((OpenMode & saga::filesystem::CreateParents) && !fs::create_directories(path)) {
                     SAGA_ADAPTOR_THROW(path.string() + 
+                      ": couldn't create the directory hierarchy", saga::DoesNotExist);
+                }
+                else if (!fs::create_directory (path)) {
+                    SAGA_ADAPTOR_THROW(path.string() + 
                       ": couldn't create the directory", saga::DoesNotExist);
                 }
             }
@@ -119,25 +118,23 @@
 
     if (!fs::exists(path)) 
     {    
-      // create directory, if needed
-      if (data->mode_ & saga::filesystem::Create) {
-            try {
-                if (!fs::create_directory (path)) {
-                      SAGA_ADAPTOR_THROW(path.string () + 
-                        ": couldn't create the directory", saga::DoesNotExist);
-                }
-            }
-            catch (boost::system::system_error const& e) {
+        try {
+            // create directory, if needed
+            if ((OpenMode & saga::filesystem::CreateParents) && !fs::create_directories (path)) {
                 SAGA_ADAPTOR_THROW(path.string () + 
-                  ": couldn't create the directory (" + e.what() + ")", 
-                  saga::DoesNotExist);
+                    ": couldn't create the directory hierarchy", saga::DoesNotExist);
             }
-      }
-      else if ( (data->mode_ & saga::filesystem::CreateParents) && ! fs::create_directories (path)) {
-        SAGA_ADAPTOR_THROW(path.string () + 
-          ": couldn't create the directory hierarchy", saga::DoesNotExist);
-      }
-    }      
+            else if ((OpenMode & saga::filesystem::Create) && !fs::create_directory (path)) {
+                  SAGA_ADAPTOR_THROW(path.string() + 
+                      ": couldn't create the directory", saga::DoesNotExist);
+            }
+        }
+        catch (boost::system::system_error const& e) {
+            SAGA_ADAPTOR_THROW(path.string () + 
+              ": couldn't create the directory (" + e.what() + ")", 
+              saga::DoesNotExist);
+        }
+    }
 
     // we don't need to create the directory twice
     data->mode_ &= ~(saga::filesystem::Create | saga::filesystem::CreateParents);



More information about the saga-devel mailing list