diff --git a/src/rime/dict/level_db.cc b/src/rime/dict/level_db.cc index 21c106611..e0bd3392f 100644 --- a/src/rime/dict/level_db.cc +++ b/src/rime/dict/level_db.cc @@ -234,10 +234,7 @@ bool LevelDb::Recover() { auto status = leveldb::RepairDB(file_name(), leveldb::Options()); if (status.ok()) { LOG(INFO) << "repair finished."; - if (Close() && Open()) { - LOG(INFO) << "db recovery successful."; - return true; - } + return true; } LOG(ERROR) << "db recovery failed: " << status.ToString(); return false; diff --git a/src/rime/dict/user_db_recovery_task.cc b/src/rime/dict/user_db_recovery_task.cc index d2286db51..83699b7ca 100644 --- a/src/rime/dict/user_db_recovery_task.cc +++ b/src/rime/dict/user_db_recovery_task.cc @@ -30,15 +30,15 @@ bool UserDbRecoveryTask::Run(Deployer* deployer) { db_->enable(); } BOOST_SCOPE_EXIT_END - // - auto r = As(db_); - if (r && r->Recover()) { - return true; - } + if (db_->loaded()) { LOG(WARNING) << "cannot recover loaded db '" << db_->name() << "'."; return false; } + auto r = As(db_); + if (r && r->Recover()) { + return true; + } // repair didn't work on the damanged db file; remove and recreate it LOG(INFO) << "recreating db file."; if (db_->Exists()) { diff --git a/src/rime/dict/user_dictionary.cc b/src/rime/dict/user_dictionary.cc index 6d09ff686..0da5f213c 100644 --- a/src/rime/dict/user_dictionary.cc +++ b/src/rime/dict/user_dictionary.cc @@ -153,7 +153,7 @@ void UserDictionary::Attach(const an& table, } bool UserDictionary::Load() { - if (!db_) + if (!db_ || db_->disabled()) return false; if (!db_->loaded() && !db_->Open()) { // try to recover managed db in available work thread @@ -165,9 +165,7 @@ bool UserDictionary::Load() { } return false; } - if (!FetchTickCount() && !Initialize()) - return false; - return true; + return FetchTickCount() || Initialize(); } bool UserDictionary::loaded() const {