From e79110822efdc5fef27b1b24232a0655359e7df3 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Sat, 23 Feb 2013 23:51:02 +0100 Subject: remove duplicate bitdb.Open() code from init - remove code from step 7, which we already have in step 5 of init --- src/init.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index f6485c3b1..11b7554ed 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -733,15 +733,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)) -- cgit v1.2.3 From 1859aafef0a273e27e886646e36140cc5e375ee1 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 24 Apr 2013 00:41:04 +0200 Subject: Try moving database/ away in case of failure --- src/init.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 11b7554ed..48495c446 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -605,8 +605,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")) -- cgit v1.2.3