Skip to content

Commit 7f68e81

Browse files
Fix #32
1 parent 4a16595 commit 7f68e81

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/main.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,16 @@ int main(int argc, char** argv) {
114114
while (true) {
115115
std::string random_str = "tmp." + spring::random_string(10);
116116
temp_dir = working_dir + "/" + random_str + '/';
117-
if (!boost::filesystem::exists(temp_dir)) break;
118-
}
119-
if (!boost::filesystem::create_directory(temp_dir)) {
120-
throw std::runtime_error("Cannot create temporary directory.");
117+
if (!boost::filesystem::exists(temp_dir)) {
118+
if (boost::filesystem::create_directory(temp_dir)) {
119+
// successfully created directory, break
120+
break;
121+
}
122+
// otherwise keep trying (it is possible the creation failed because another
123+
// process created the directory in that very instant)
124+
// Note that boost will throw a runtime error if the creation fails due to
125+
// permission issue
126+
}
121127
}
122128
std::cout << "Temporary directory: " << temp_dir << "\n";
123129

0 commit comments

Comments
 (0)