From 8e2b2d99a72d64815e5aec0396593c053124a863 Mon Sep 17 00:00:00 2001 From: "Peter D. Barnes, Jr." Date: Fri, 13 Apr 2018 17:02:12 -0700 Subject: [PATCH] core: refactor SystemPath::MakeDirectories Addition of bool makeDirErr is preparation for a Windows clause --- src/core/model/system-path.cc | 28 ++++++++++++++++------------ src/core/model/system-path.h | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) 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,