summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-03-12 14:58:34 +0800
committerPeng Wu <alexepico@gmail.com>2012-03-12 14:59:49 +0800
commitee803d04c74654b3fec3f4857ad31648da83a83b (patch)
tree53858541875c79de3e9ce1f88a23e8d1bc5acd40
parente939e37b1a48302b9bf2c44d403b907f3f42e118 (diff)
downloadlibpinyin-ee803d04c74654b3fec3f4857ad31648da83a83b.zip
libpinyin-ee803d04c74654b3fec3f4857ad31648da83a83b.tar.gz
libpinyin-ee803d04c74654b3fec3f4857ad31648da83a83b.tar.xz
continue improves pinyin_save
-rw-r--r--src/pinyin.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 4ede459..5257c49 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -195,10 +195,15 @@ bool pinyin_save(pinyin_context_t * context){
"gb_char.bin", NULL);
oldchunk->load(filename);
g_free(filename);
+
context->m_phrase_index->diff(1, oldchunk, newlog);
+ gchar * tmpfilename = g_build_filename(context->m_user_dir,
+ "gb_char.dbin.tmp", NULL);
filename = g_build_filename(context->m_user_dir,
"gb_char.dbin", NULL);
- newlog->save(filename);
+ newlog->save(tmpfilename);
+ rename(tmpfilename, filename);
+ g_free(tmpfilename);
g_free(filename);
delete newlog;
@@ -209,14 +214,18 @@ bool pinyin_save(pinyin_context_t * context){
g_free(filename);
context->m_phrase_index->diff(2, oldchunk, newlog);
+ tmpfilename = g_build_filename(context->m_user_dir,
+ "gbk_char.dbin.tmp", NULL);
filename = g_build_filename(context->m_user_dir,
"gbk_char.dbin", NULL);
- newlog->save(filename);
+ newlog->save(tmpfilename);
+ rename(tmpfilename, filename);
+ g_free(tmpfilename);
g_free(filename);
delete newlog;
- gchar * tmpfilename = g_build_filename(context->m_user_dir,
- "user.db.tmp", NULL);
+ tmpfilename = g_build_filename(context->m_user_dir,
+ "user.db.tmp", NULL);
filename = g_build_filename(context->m_user_dir, "user.db", NULL);
context->m_user_bigram->save_db(tmpfilename);
rename(tmpfilename, filename);