core: refactor SystemPath::MakeDirectories

Addition of bool makeDirErr is preparation for a Windows clause
This commit is contained in:
Peter D. Barnes, Jr.
2018-04-13 17:02:12 -07:00
parent f4d579b911
commit 8e2b2d99a7
2 changed files with 17 additions and 13 deletions

View File

@@ -331,25 +331,29 @@ MakeDirectories (std::string path)
// Make sure all directories on the path exist
std::list<std::string> elements = Split (path);
for (std::list<std::string>::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

View File

@@ -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<std::string>::const_iterator begin,