Remove database/ after clean shutdown

This commit is contained in:
Pieter Wuille 2013-04-24 00:43:14 +02:00
parent 1859aafef0
commit ccda03b570
2 changed files with 7 additions and 5 deletions

View file

@ -38,7 +38,7 @@ void CDBEnv::EnvShutdown()
if (ret != 0) if (ret != 0)
printf("EnvShutdown exception: %s (%d)\n", DbEnv::strerror(ret), ret); printf("EnvShutdown exception: %s (%d)\n", DbEnv::strerror(ret), ret);
if (!fMockDb) if (!fMockDb)
DbEnv(0).remove(strPath.c_str(), 0); DbEnv(0).remove(path.string().c_str(), 0);
} }
CDBEnv::CDBEnv() : dbenv(DB_CXX_NO_EXCEPTIONS) CDBEnv::CDBEnv() : dbenv(DB_CXX_NO_EXCEPTIONS)
@ -57,14 +57,14 @@ void CDBEnv::Close()
EnvShutdown(); EnvShutdown();
} }
bool CDBEnv::Open(const boost::filesystem::path& path) bool CDBEnv::Open(const boost::filesystem::path& pathIn)
{ {
if (fDbEnvInit) if (fDbEnvInit)
return true; return true;
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
strPath = path.string(); path = pathIn;
filesystem::path pathLogDir = path / "database"; filesystem::path pathLogDir = path / "database";
filesystem::create_directory(pathLogDir); filesystem::create_directory(pathLogDir);
filesystem::path pathErrorFile = path / "db.log"; filesystem::path pathErrorFile = path / "db.log";
@ -84,7 +84,7 @@ bool CDBEnv::Open(const boost::filesystem::path& path)
dbenv.set_flags(DB_AUTO_COMMIT, 1); dbenv.set_flags(DB_AUTO_COMMIT, 1);
dbenv.set_flags(DB_TXN_WRITE_NOSYNC, 1); dbenv.set_flags(DB_TXN_WRITE_NOSYNC, 1);
dbenv.log_set_config(DB_LOG_AUTO_REMOVE, 1); dbenv.log_set_config(DB_LOG_AUTO_REMOVE, 1);
int ret = dbenv.open(strPath.c_str(), int ret = dbenv.open(path.string().c_str(),
DB_CREATE | DB_CREATE |
DB_INIT_LOCK | DB_INIT_LOCK |
DB_INIT_LOG | DB_INIT_LOG |
@ -456,6 +456,8 @@ void CDBEnv::Flush(bool fShutdown)
{ {
dbenv.log_archive(&listp, DB_ARCH_REMOVE); dbenv.log_archive(&listp, DB_ARCH_REMOVE);
Close(); Close();
if (!fMockDb)
boost::filesystem::remove_all(path / "database");
} }
} }
} }

View file

@ -33,7 +33,7 @@ class CDBEnv
private: private:
bool fDbEnvInit; bool fDbEnvInit;
bool fMockDb; bool fMockDb;
std::string strPath; boost::filesystem::path path;
void EnvShutdown(); void EnvShutdown();