Mercurial > hg > bitcoin
diff src/db.cpp @ 2207:34d7dc611b26 draft
Use filesystem::path instead of manual string tinkering
Where possible, use boost::filesystem::path instead of std::string or
char* for filenames. This avoids a lot of manual string tinkering, in
favor of path::operator/.
GetDataDir is also reworked significantly, it now only keeps two cached
directory names (the network-specific data dir, and the root data dir),
which are decided through a parameter instead of pre-initialized global
variables.
Finally, remove the "upgrade from 0.1.5" case where a debug.log in the
current directory has to be removed.
author | Pieter Wuille <pieter.wuille@gmail.com> |
---|---|
date | Mon, 09 Apr 2012 23:50:56 +0200 |
parents | 8a17a73180e3 |
children | b26677f778d1 |
line wrap: on
line diff
--- a/src/db.cpp +++ b/src/db.cpp @@ -43,7 +43,7 @@ { printf("EnvShutdown exception: %s (%d)\n", e.what(), e.get_errno()); } - DbEnv(0).remove(GetDataDir().c_str(), 0); + DbEnv(0).remove(GetDataDir().string().c_str(), 0); } class CDBInit @@ -60,7 +60,7 @@ instance_of_cdbinit; -CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL) +CDB::CDB(const char *pszFile, const char* pszMode) : pdb(NULL) { int ret; if (pszFile == NULL) @@ -78,10 +78,10 @@ { if (fShutdown) return; - string strDataDir = GetDataDir(); - filesystem::path pathLogDir(strDataDir + "/database"); + filesystem::path pathDataDir = GetDataDir(); + filesystem::path pathLogDir = pathDataDir / "database"; filesystem::create_directory(pathLogDir); - filesystem::path pathErrorFile(strDataDir + "/db.log"); + filesystem::path pathErrorFile = pathDataDir / "db.log"; printf("dbenv.open LogDir=%s ErrorFile=%s\n", pathLogDir.string().c_str(), pathErrorFile.string().c_str()); int nDbCache = GetArg("-dbcache", 25); @@ -94,7 +94,7 @@ dbenv.set_errfile(fopen(pathErrorFile.string().c_str(), "a")); /// debug dbenv.set_flags(DB_AUTO_COMMIT, 1); dbenv.log_set_config(DB_LOG_AUTO_REMOVE, 1); - ret = dbenv.open(strDataDir.c_str(), + ret = dbenv.open(pathDataDir.string().c_str(), DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | @@ -1087,13 +1087,7 @@ return DB_NEED_REWRITE; if (nFileVersion < CLIENT_VERSION) // Update - { - // Get rid of old debug.log file in current directory - if (nFileVersion <= 105 && !pszSetDataDir[0]) - unlink("debug.log"); - WriteVersion(CLIENT_VERSION); - } return DB_LOAD_OK; } @@ -1176,10 +1170,10 @@ mapFileUseCount.erase(wallet.strWalletFile); // Copy wallet.dat - filesystem::path pathSrc(GetDataDir() + "/" + wallet.strWalletFile); + filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile; filesystem::path pathDest(strDest); if (filesystem::is_directory(pathDest)) - pathDest = pathDest / wallet.strWalletFile; + pathDest /= wallet.strWalletFile; try { #if BOOST_VERSION >= 104000