Browse Source

Update TransientDirectory.cpp

switched to no-throw version of remove_all()
cl-refactor
gluk256 10 years ago
parent
commit
ff1f386df8
  1. 26
      libdevcore/TransientDirectory.cpp

26
libdevcore/TransientDirectory.cpp

@ -24,6 +24,7 @@
#include "Exceptions.h" #include "Exceptions.h"
#include "TransientDirectory.h" #include "TransientDirectory.h"
#include "CommonIO.h" #include "CommonIO.h"
#include "Log.h"
using namespace std; using namespace std;
using namespace dev; using namespace dev;
@ -43,16 +44,19 @@ TransientDirectory::TransientDirectory(std::string const& _path):
TransientDirectory::~TransientDirectory() TransientDirectory::~TransientDirectory()
{ {
for (int i = 0; i < 3; ++i) boost::system::error_code ec;
{ boost::filesystem::remove_all(m_path, ec);
try if (0 == ec)
{ return;
boost::filesystem::remove_all(m_path);
break; // In some cases, antivirus runnig on Windows will scan all the newly created directories.
} // As a consequence, directory is locked and can not be deleted immediately.
catch (...) // Retry after 10 milliseconds usually is successful.
{ // This will help our tests run smoothly in such environment.
this_thread::sleep_for(chrono::milliseconds(10)); this_thread::sleep_for(chrono::milliseconds(10));
}
} ec.clear();
boost::filesystem::remove_all(m_path, ec);
if (ec != 0)
cwarn << "Failed to delete directory '" << m_path << "': " << ec.message();
} }

Loading…
Cancel
Save