diff --git a/src/core/model/system-path.cc b/src/core/model/system-path.cc index fdb8855f4..00965dee5 100644 --- a/src/core/model/system-path.cc +++ b/src/core/model/system-path.cc @@ -331,25 +331,29 @@ MakeDirectories (std::string path) // Make sure all directories on the path exist std::list elements = Split (path); - for (std::list::const_iterator i = elements.begin (); i != elements.end (); ++i) + auto i = elements.begin (); + while (i != elements.end ()) { + if (*i == "") + { + NS_LOG_LOGIC ("skipping empty directory name"); + ++i; + continue; + } + NS_LOG_LOGIC ("creating directory " << *i); + ++i; // Now points to one past the directory we want to create std::string tmp = Join (elements.begin (), i); + bool makeDirErr = false; + #if defined(HAVE_MKDIR_H) - if (mkdir (tmp.c_str (), S_IRWXU)) + makeDirErr = mkdir (tmp.c_str (), S_IRWXU); +#endif + + if (makeDirErr) { NS_LOG_ERROR ("failed creating directory " << tmp); } -#endif } - - // Make the final directory. Is this redundant with last iteration above? -#if defined(HAVE_MKDIR_H) - if (mkdir (path.c_str (), S_IRWXU)) - { - NS_LOG_ERROR ("failed creating directory " << path); - } -#endif - } } // namespace SystemPath diff --git a/src/core/model/system-path.h b/src/core/model/system-path.h index 162aa8a76..8d7abc264 100644 --- a/src/core/model/system-path.h +++ b/src/core/model/system-path.h @@ -87,7 +87,7 @@ namespace SystemPath { * * \ingroup systempath * \param [in] begin Iterator to first element to join - * \param [in] end Iterator to last element to join + * \param [in] end Iterator to one past the last element to join * \return A path that is a concatenation of all the input elements. */ std::string Join (std::list::const_iterator begin,