-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathtest_util.cpp
More file actions
29 lines (22 loc) · 897 Bytes
/
test_util.cpp
File metadata and controls
29 lines (22 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "test_util.h"
#include <string>
#include <string.h>
#include <vector>
std::filesystem::path make_temporary_directory(std::optional<std::string> pattern) {
// note: previously, the (insecure) boost::filesystem::unique_path() was used to generate a temporary directory
// this function was never integrated into std::filesystem, so we use the good ol' POSIX function mkdtemp
static const std::string defaultPattern = "/tmp/linuxdeploy-tests-XXXXXX";
const std::string tmpl = [pattern]() {
if (pattern.has_value()) {
return pattern.value();
}
return defaultPattern;
}();
std::vector<char> tmplC(tmpl.size() + 1);
strcpy(tmplC.data(), tmpl.c_str());
auto tmpDir = mkdtemp(tmplC.data());
if (tmpDir == nullptr) {
throw std::runtime_error("could not create temporary directory");
}
return tmpDir;
}