File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments