void Fixture::mkdirsChecked()

in src/oomd/util/Fixture.cpp [92:117]


void Fixture::mkdirsChecked(
    const std::string& path,
    const std::string& prefix) {
  auto dirs = Util::split(path, '/');
  std::string prefix_path;
  // two slashes after each component
  prefix_path.reserve(path.size() + prefix.size() + 2);
  if (path.size() && path[0] == '/') {
    prefix_path += "/";
  } else if (prefix != "") {
    prefix_path += prefix + "/";
  }
  for (const auto& dir : dirs) {
    if (dir == "") {
      continue;
    }
    prefix_path += dir + "/";
    if (::mkdir(prefix_path.c_str(), 0777) == -1 && errno != EEXIST) {
      std::array<char, 1024> buf;
      buf[0] = '\0';
      throw std::runtime_error(
          prefix_path +
          ": mkdir failed: " + ::strerror_r(errno, buf.data(), buf.size()));
    }
  }
}