Save and restore current_path in TestingSetup constructor/destructor

This commit is contained in:
Charlie O'Keefe 2018-10-31 14:13:50 -06:00
parent ab24201507
commit 0ade29546f
2 changed files with 9 additions and 0 deletions

View File

@ -93,6 +93,10 @@ TestingSetup::TestingSetup()
bitdb.MakeMock();
RegisterWalletRPCCommands(tableRPC);
#endif
// Save current path, in case a test changes it
orig_current_path = boost::filesystem::current_path();
ClearDatadirCache();
pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
boost::filesystem::create_directories(pathTemp);
@ -131,6 +135,10 @@ TestingSetup::~TestingSetup()
bitdb.Flush(true);
bitdb.Reset();
#endif
// Restore the previous current path so temporary directory can be deleted
boost::filesystem::current_path(orig_current_path);
boost::filesystem::remove_all(pathTemp);
}

View File

@ -30,6 +30,7 @@ struct JoinSplitTestingSetup: public BasicTestingSetup {
*/
struct TestingSetup: public JoinSplitTestingSetup {
CCoinsViewDB *pcoinsdbview;
boost::filesystem::path orig_current_path;
boost::filesystem::path pathTemp;
boost::thread_group threadGroup;