Skip to content

Commit 0f3d0df

Browse files
committed
fix(dict): issues with user db recovery
1 parent 89b7df2 commit 0f3d0df

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

src/rime/dict/level_db.cc

+1-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ bool LevelDb::Recover() {
234234
auto status = leveldb::RepairDB(file_name(), leveldb::Options());
235235
if (status.ok()) {
236236
LOG(INFO) << "repair finished.";
237-
if (Close() && Open()) {
238-
LOG(INFO) << "db recovery successful.";
239-
return true;
240-
}
237+
return true;
241238
}
242239
LOG(ERROR) << "db recovery failed: " << status.ToString();
243240
return false;

src/rime/dict/user_db_recovery_task.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ bool UserDbRecoveryTask::Run(Deployer* deployer) {
3030
db_->enable();
3131
}
3232
BOOST_SCOPE_EXIT_END
33-
//
34-
auto r = As<Recoverable>(db_);
35-
if (r && r->Recover()) {
36-
return true;
37-
}
33+
3834
if (db_->loaded()) {
3935
LOG(WARNING) << "cannot recover loaded db '" << db_->name() << "'.";
4036
return false;
4137
}
38+
auto r = As<Recoverable>(db_);
39+
if (r && r->Recover()) {
40+
return true;
41+
}
4242
// repair didn't work on the damanged db file; remove and recreate it
4343
LOG(INFO) << "recreating db file.";
4444
if (db_->Exists()) {

src/rime/dict/user_dictionary.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void UserDictionary::Attach(const an<Table>& table,
153153
}
154154

155155
bool UserDictionary::Load() {
156-
if (!db_)
156+
if (!db_ || db_->disabled())
157157
return false;
158158
if (!db_->loaded() && !db_->Open()) {
159159
// try to recover managed db in available work thread
@@ -165,9 +165,7 @@ bool UserDictionary::Load() {
165165
}
166166
return false;
167167
}
168-
if (!FetchTickCount() && !Initialize())
169-
return false;
170-
return true;
168+
return FetchTickCount() || Initialize();
171169
}
172170

173171
bool UserDictionary::loaded() const {

0 commit comments

Comments
 (0)