Browse Source

Update TransientDirectory.cpp

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

28
libdevcore/TransientDirectory.cpp

@ -24,6 +24,7 @@
#include "Exceptions.h"
#include "TransientDirectory.h"
#include "CommonIO.h"
#include "Log.h"
using namespace std;
using namespace dev;
@ -43,16 +44,19 @@ TransientDirectory::TransientDirectory(std::string const& _path):
TransientDirectory::~TransientDirectory()
{
for (int i = 0; i < 3; ++i)
{
try
{
boost::filesystem::remove_all(m_path);
break;
}
catch (...)
{
this_thread::sleep_for(chrono::milliseconds(10));
}
}
boost::system::error_code ec;
boost::filesystem::remove_all(m_path, ec);
if (0 == ec)
return;
// 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.
// Retry after 10 milliseconds usually is successful.
// This will help our tests run smoothly in such environment.
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