18 #if !defined(_MSC_VER) 39 char temp_file_path[
MAX_PATH + 1] = { 0 };
40 unsigned success = ::GetTempFileName(
".", sample, 0, temp_file_path);
42 throw common::ErrnoException(
43 "Could not allocate temporary directory " 47 if (!DeleteFile(temp_file_path)) {
48 throw common::ErrnoException(
49 "Could not create temporary directory " 53 if (!CreateDirectory(temp_file_path,
nullptr)) {
54 throw common::ErrnoException(
55 "Could not create temporary directory " 59 return temp_file_path;
65 WIN32_FIND_DATA ff_data;
66 HANDLE h = FindFirstFile((tmp_dir +
"\\*").c_str(), &ff_data);
68 if (h == INVALID_HANDLE_VALUE) {
69 throw common::ErrnoException(
74 if (!(ff_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
75 std::string path = tmp_dir +
"\\" + ff_data.cFileName;
77 if (!DeleteFile(path.c_str())) {
78 sLOG1 <<
"Could not unlink temporary file" << path
79 <<
":" << strerror(errno);
82 }
while (FindNextFile(h, &ff_data) != 0);
84 DWORD e = GetLastError();
85 if (e != ERROR_NO_MORE_FILES) {
86 throw common::ErrnoException(
90 if (!do_rmdir)
return;
92 if (!RemoveDirectory(tmp_dir.c_str())) {
93 throw common::ErrnoException(
94 "Could not remove temporary directory " + tmp_dir);
105 char* p = mkdtemp(const_cast<char*>(tmp_dir.c_str()));
109 "Could create temporary directory " + tmp_dir);
117 DIR* d = opendir(tmp_dir.c_str());
120 "Could open temporary directory " + tmp_dir);
126 if (de->d_name[0] ==
'.')
continue;
129 int r = unlink(path.c_str());
131 sLOG1 <<
"Could not unlink temporary file" << path
132 <<
":" << strerror(errno);
137 if (!do_rmdir)
return;
139 if (rmdir(tmp_dir.c_str()) != 0) {
140 sLOG1 <<
"Could not unlink temporary directory" << tmp_dir
141 <<
":" << strerror(errno);
An Exception which is thrown on system errors and contains errno information.
static by_string to_string(int val)
convert to string
struct dirent * ts_readdir(DIR *dirp)
mutex-locked readdir() call
static std::string make_directory(const char *sample="thrill-testsuite-")
Create a temporary directory, returns its name without trailing /.
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
static void wipe_directory(const std::string &tmp_dir, bool do_rmdir)
wipe temporary directory NON RECURSIVELY!