diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2013-04-24 00:41:04 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2013-04-24 01:37:19 +0200 |
commit | 1859aafef0a273e27e886646e36140cc5e375ee1 (patch) | |
tree | 2d3198020445ad827635e0395b06ac6d60a7f79a /src/init.cpp | |
parent | e79110822efdc5fef27b1b24232a0655359e7df3 (diff) |
Try moving database/ away in case of failure
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/init.cpp b/src/init.cpp index 11b7554ed1..48495c446a 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")) |