17 #ifndef __STOUT_OS_WINDOWS_MKDTEMP_HPP__
18 #define __STOUT_OS_WINDOWS_MKDTEMP_HPP__
48 static const char postfixTemplate[] =
"XXXXXX";
49 static const size_t postfixSize =
sizeof(postfixTemplate) - 1;
53 "Invalid template passed to `os::mkdtemp`: template '" + path +
54 "' should end with 6 'X' characters");
57 static const char alphabet[] =
59 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
60 "abcdefghijklmnopqrstuvwxyz";
66 static const size_t maxAlphabetIndex =
sizeof(alphabet) - 2;
68 std::string postfix(postfixTemplate);
69 static thread_local std::mt19937 generator((std::random_device())());
71 for (
int i = 0; i < postfixSize; ++i) {
72 int index = generator() % maxAlphabetIndex;
73 postfix[i] = alphabet[
index];
77 std::string tempPath = path
78 .substr(0, path.length() - postfixSize)
93 #endif // __STOUT_OS_WINDOWS_MKDTEMP_HPP__
bool endsWith(const std::string &s, const std::string &suffix)
Definition: strings.hpp:393
Definition: errorbase.hpp:35
std::string join(const std::string &path1, const std::string &path2, const char _separator=os::PATH_SEPARATOR)
Definition: path.hpp:56
Result< int > index(const std::string &link)
Try< Nothing > mkdir(const std::string &directory, bool recursive=true)
Definition: mkdir.hpp:31
static Try error(const E &e)
Definition: try.hpp:42
bool isError() const
Definition: try.hpp:71
std::string temp()
Definition: temp.hpp:27
Try< Nothing > append(const std::string &path, const google::protobuf::Message &message)
Definition: protobuf.hpp:135
Try< std::string > mkdtemp(const std::string &path=path::join(os::temp(),"XXXXXX"))
Definition: mkdtemp.hpp:38