Skip to content

Commit

Permalink
Fix #32
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamchandak94 authored May 27, 2023
1 parent 4a16595 commit 7f68e81
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,16 @@ int main(int argc, char** argv) {
while (true) {
std::string random_str = "tmp." + spring::random_string(10);
temp_dir = working_dir + "/" + random_str + '/';
if (!boost::filesystem::exists(temp_dir)) break;
}
if (!boost::filesystem::create_directory(temp_dir)) {
throw std::runtime_error("Cannot create temporary directory.");
if (!boost::filesystem::exists(temp_dir)) {
if (boost::filesystem::create_directory(temp_dir)) {
// successfully created directory, break
break;
}
// otherwise keep trying (it is possible the creation failed because another
// process created the directory in that very instant)
// Note that boost will throw a runtime error if the creation fails due to
// permission issue
}
}
std::cout << "Temporary directory: " << temp_dir << "\n";

Expand Down

0 comments on commit 7f68e81

Please sign in to comment.