improves pinyin_save
authorPeng Wu <alexepico@gmail.com>
Mon, 12 Mar 2012 05:55:53 +0000 (13:55 +0800)
committerPeng Wu <alexepico@gmail.com>
Mon, 12 Mar 2012 05:55:53 +0000 (13:55 +0800)
src/pinyin.cpp

index 5f6ebc63542f639baf304ccbdbac5fb99972973c..b8726f6e91fee065e92b2297c287688ef8ff45f8 100644 (file)
@@ -215,8 +215,12 @@ bool pinyin_save(pinyin_context_t * context){
     g_free(filename);
     delete newlog;
 
+    gchar * 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(filename);
+    context->m_user_bigram->save_db(tmpfilename);
+    rename(tmpfilename, filename);
+    g_free(tmpfilename);
     g_free(filename);
 
     mark_version(context->m_user_dir);