aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2013-05-03 15:17:33 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2013-05-03 15:17:33 -0700
commit674ae7a26fbcd97a37e7a6fb2e26d186e872e354 (patch)
treec0712b4839fd1518db5bdf432868d7f9c95256fc /src/init.cpp
parent979a22a7a07b8336a3762a09fd035f58d3d4d06f (diff)
parentccda03b57022369c4352d0f5a816cff9ace833e6 (diff)
Merge pull request #2558 from sipa/nodbdir
Some database/-related recovery improvements
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 3775790b68..02997cd357 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -632,8 +632,22 @@ bool AppInit2(boost::thread_group& threadGroup)
if (!bitdb.Open(GetDataDir()))
{
- string msg = strprintf(_("Error initializing wallet database environment %s!"), strDataDir.c_str());
- return InitError(msg);
+ // try moving the database env out of the way
+ boost::filesystem::path pathDatabase = GetDataDir() / "database";
+ boost::filesystem::path pathDatabaseBak = GetDataDir() / strprintf("database.%"PRI64d".bak", GetTime());
+ try {
+ boost::filesystem::rename(pathDatabase, pathDatabaseBak);
+ printf("Moved old %s to %s. Retrying.\n", pathDatabase.string().c_str(), pathDatabaseBak.string().c_str());
+ } catch(boost::filesystem::filesystem_error &error) {
+ // failure is ok (well, not really, but it's not worse than what we started with)
+ }
+
+ // try again
+ if (!bitdb.Open(GetDataDir())) {
+ // if it still fails, it probably means we can't even create the database env
+ string msg = strprintf(_("Error initializing wallet database environment %s!"), strDataDir.c_str());
+ return InitError(msg);
+ }
}
if (GetBoolArg("-salvagewallet"))
@@ -760,15 +774,6 @@ bool AppInit2(boost::thread_group& threadGroup)
fReindex = GetBoolArg("-reindex");
- // Todo: Check if needed, because in step 5 we do the same
- if (!bitdb.Open(GetDataDir()))
- {
- string msg = strprintf(_("Error initializing database environment %s!"
- " To recover, BACKUP THAT DIRECTORY, then remove"
- " everything from it except for wallet.dat."), strDataDir.c_str());
- return InitError(msg);
- }
-
// Upgrading to 0.8; hard-link the old blknnnn.dat files into /blocks/
filesystem::path blocksDir = GetDataDir() / "blocks";
if (!filesystem::exists(blocksDir))