summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-10-27 18:05:44 +0800
committerPeng Wu <alexepico@gmail.com>2011-10-27 18:06:08 +0800
commit81ca3def70f06419f90c8db0246fad614ec9d11a (patch)
treeb49624a1d685b5291304f79a505a698c0d4eaeba
parentcdd9f5355a24f59f3aa587842d5b0a7e9fce4394 (diff)
downloadlibpinyin-81ca3def70f06419f90c8db0246fad614ec9d11a.zip
libpinyin-81ca3def70f06419f90c8db0246fad614ec9d11a.tar.gz
libpinyin-81ca3def70f06419f90c8db0246fad614ec9d11a.tar.xz
fixes save_db
-rw-r--r--src/pinyin.cpp15
-rw-r--r--src/storage/ngram.cpp3
2 files changed, 17 insertions, 1 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 46269e1..8832321 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -63,6 +63,7 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
fprintf(stderr, "open %s failed!\n", filename);
return NULL;
}
+ g_free(filename);
context->m_pinyin_table->load(chunk);
context->m_validator.initialize(context->m_pinyin_table);
@@ -77,6 +78,7 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
fprintf(stderr, "open %s failed!\n", filename);
return NULL;
}
+ g_free(filename);
context->m_phrase_table->load(chunk);
context->m_phrase_index = new FacadePhraseIndex;
@@ -86,9 +88,11 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
fprintf(stderr, "open %s failed!\n", filename);
return NULL;
}
+ g_free(filename);
context->m_phrase_index->load(1, chunk);
filename = g_build_filename(context->m_user_dir, "gb_char.dbin", NULL);
log->load(filename);
+ g_free(filename);
context->m_phrase_index->merge(1, log);
log = new MemoryChunk; chunk = new MemoryChunk;
@@ -97,17 +101,22 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
fprintf(stderr, "open %s failed!\n", filename);
return NULL;
}
+ g_free(filename);
context->m_phrase_index->load(2, chunk);
filename = g_build_filename(context->m_user_dir, "gbk_char.dbin", NULL);
log->load(filename);
+ g_free(filename);
context->m_phrase_index->merge(2, log);
context->m_system_bigram = new Bigram;
filename = g_build_filename(context->m_system_dir, "bigram.db", NULL);
context->m_system_bigram->attach(filename, ATTACH_READONLY);
+ g_free(filename);
+
context->m_user_bigram = new Bigram;
filename = g_build_filename(context->m_user_dir, "user.db", NULL);
context->m_user_bigram->load_db(filename);
+ g_free(filename);
context->m_pinyin_lookup = new PinyinLookup
( &(context->m_custom), context->m_pinyin_table,
@@ -134,24 +143,30 @@ bool pinyin_save(pinyin_context_t * context){
gchar * filename = g_build_filename(context->m_system_dir,
"gb_char.bin", NULL);
oldchunk->load(filename);
+ g_free(filename);
context->m_phrase_index->diff(1, oldchunk, newlog);
filename = g_build_filename(context->m_user_dir,
"gb_char.dbin", NULL);
newlog->save(filename);
+ g_free(filename);
delete newlog;
oldchunk = new MemoryChunk; newlog = new MemoryChunk;
filename = g_build_filename(context->m_system_dir,
"gbk_char.bin", NULL);
oldchunk->load(filename);
+ g_free(filename);
+
context->m_phrase_index->diff(2, oldchunk, newlog);
filename = g_build_filename(context->m_user_dir,
"gbk_char.dbin", NULL);
newlog->save(filename);
+ g_free(filename);
delete newlog;
filename = g_build_filename(context->m_user_dir, "user.db", NULL);
context->m_user_bigram->save_db(filename);
+ g_free(filename);
context->m_modified = false;
return true;
diff --git a/src/storage/ngram.cpp b/src/storage/ngram.cpp
index fedd744..f7dd347 100644
--- a/src/storage/ngram.cpp
+++ b/src/storage/ngram.cpp
@@ -20,6 +20,7 @@
*/
#include <stdio.h>
+#include <errno.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "memory_chunk.h"
@@ -273,7 +274,7 @@ bool Bigram::save_db(const char * dbfile){
DB * tmp_db = NULL;
int ret = g_unlink(dbfile);
- if ( ret != 0 )
+ if ( ret != 0 && errno != ENOENT)
return false;
ret = db_create(&tmp_db, NULL, 0);