13 #ifndef __STOUT_OS_POSIX_MKDIR_HPP__ 14 #define __STOUT_OS_POSIX_MKDIR_HPP__ 43 const std::string& directory,
44 bool recursive =
true,
48 if (::
mkdir(directory.c_str(), 0755) < 0) {
53 const std::string parent =
Path(directory).
dirname();
57 "Failed to fsync directory '" + parent +
"': " + fsync.
error());
61 std::vector<std::string> tokens =
71 foreach (
const std::string& token, tokens) {
73 if (::
mkdir(path.c_str(), 0755) < 0) {
74 if (errno != EEXIST) {
82 "Failed to fsync directory '" + parent +
"': " + fsync.
error());
95 #endif // __STOUT_OS_POSIX_MKDIR_HPP__
Definition: nothing.hpp:16
Definition: errorbase.hpp:36
Definition: errorbase.hpp:50
Definition: posix_signalhandler.hpp:23
std::vector< std::string > tokenize(const std::string &s, const std::string &delims, const Option< size_t > &maxTokens=None())
Definition: strings.hpp:139
Try< Nothing > mkdir(const std::string &directory, bool recursive=true, bool sync=false)
Definition: mkdir.hpp:42
Represents a POSIX or Windows file system path and offers common path manipulations.
Definition: path.hpp:212
static Try error(const E &e)
Definition: try.hpp:43
std::string dirname() const
Extracts the component up to, but not including, the final '/'.
Definition: path.hpp:308
Try< Nothing > fsync(int fd)
Definition: fsync.hpp:29
bool isError() const
Definition: try.hpp:78
std::string stringify(int flags)
constexpr char PATH_SEPARATOR
Definition: constants.hpp:24