core: refactor SystemPath::MakeDirectories
Addition of bool makeDirErr is preparation for a Windows clause
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user