void mkdirSafe(const std::string &path, mode_t mode)
{
- RUNNER_ASSERT_ERRNO_MSG(0 == mkdir(path.c_str(), mode),
+ RUNNER_ASSERT_ERRNO_MSG(0 == mkdir(path.c_str(), mode) || errno == EEXIST,
"mkdir for <" << path << "> with mode <" << mode << "> failed");
}
+void mktreeSafe(const std::string &path, mode_t mode)
+{
+ // Create subsequent parent directories
+ // Assume that path is absolute - i.e. starts with '/'
+ for (size_t pos = 0; (pos = path.find("/", pos + 1)) != std::string::npos; )
+ mkdirSafe(path.substr(0, pos).c_str(), mode);
+
+ mkdirSafe(path, mode);
+}
+
void creatSafe(const std::string &path, mode_t mode)
{
RUNNER_ASSERT_ERRNO_MSG(-1 != creat(path.c_str(), mode),