rpms/scim-pinyin/F-8 scim-pinyin-0.5.91-fix-load.patch, NONE, 1.1 scim-pinyin-0.5.91-save-in-temp.patch, NONE, 1.1 scim-pinyin.spec, 1.41, 1.42
Huang Peng (phuang)
fedora-extras-commits at redhat.com
Thu Nov 15 07:33:05 UTC 2007
Author: phuang
Update of /cvs/pkgs/rpms/scim-pinyin/F-8
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv19295
Modified Files:
scim-pinyin.spec
Added Files:
scim-pinyin-0.5.91-fix-load.patch
scim-pinyin-0.5.91-save-in-temp.patch
Log Message:
catch exceptions when load user data from file. Save user data in temp file at first.
scim-pinyin-0.5.91-fix-load.patch:
--- NEW FILE scim-pinyin-0.5.91-fix-load.patch ---
diff -up scim-pinyin-0.5.91/src/scim_pinyin_phrase.cpp.fix-load scim-pinyin-0.5.91/src/scim_pinyin_phrase.cpp
--- scim-pinyin-0.5.91/src/scim_pinyin_phrase.cpp.fix-load 2007-11-15 15:06:10.000000000 +0800
+++ scim-pinyin-0.5.91/src/scim_pinyin_phrase.cpp 2007-11-15 15:06:27.000000000 +0800
@@ -351,17 +351,24 @@ PinyinPhraseLib::input (std::istream &is
std::istream &is_pylib,
std::istream &is_idx)
{
- if (m_phrase_lib.input (is_lib)) {
- if (is_idx && input_pinyin_lib (*m_validator, is_pylib)) {
- if (!input_indexes (is_idx)) {
+ is_lib.exceptions (std::ifstream::failbit);
+ is_pylib.exceptions (std::ifstream::failbit);
+ is_idx.exceptions (std::ifstream::failbit);
+ try {
+ if (m_phrase_lib.input (is_lib)) {
+ if (is_idx && input_pinyin_lib (*m_validator, is_pylib)) {
+ if (!input_indexes (is_idx)) {
+ create_pinyin_index ();
+ return true;
+ }
+ } else {
create_pinyin_index ();
return true;
}
- } else {
- create_pinyin_index ();
return true;
}
- return true;
+ } catch (std::ifstream::failure e) {
+ std::cerr << "Reading pinyin phrase lib failed" << std::endl;
}
return false;
}
diff -up scim-pinyin-0.5.91/src/scim_pinyin.cpp.fix-load scim-pinyin-0.5.91/src/scim_pinyin.cpp
--- scim-pinyin-0.5.91/src/scim_pinyin.cpp.fix-load 2005-08-08 14:11:16.000000000 +0800
+++ scim-pinyin-0.5.91/src/scim_pinyin.cpp 2007-11-15 15:06:20.000000000 +0800
@@ -1561,83 +1561,92 @@ PinyinTable::input (std::istream &is)
bool binary;
if (!is) return false;
-
- is.getline (header, 40);
- if (strncmp (header,
- scim_pinyin_table_text_header,
- strlen (scim_pinyin_table_text_header)) == 0) {
- binary = false;
- } else if (strncmp (header,
- scim_pinyin_table_binary_header,
- strlen (scim_pinyin_table_binary_header)) == 0) {
- binary = true;
- } else {
- return false;
- }
+ is.exceptions (std::ifstream::failbit);
- is.getline (header, 40);
- if (strncmp (header, scim_pinyin_table_version, strlen (scim_pinyin_table_version)) != 0)
+ try {
+
+ is.getline (header, 40);
+
+ if (strncmp (header,
+ scim_pinyin_table_text_header,
+ strlen (scim_pinyin_table_text_header)) == 0) {
+ binary = false;
+ } else if (strncmp (header,
+ scim_pinyin_table_binary_header,
+ strlen (scim_pinyin_table_binary_header)) == 0) {
+ binary = true;
+ } else {
+ return false;
+ }
+
+ is.getline (header, 40);
+ if (strncmp (header, scim_pinyin_table_version, strlen (scim_pinyin_table_version)) != 0)
+ return false;
+
+ uint32 i;
+ uint32 n;
+ PinyinEntryVector::iterator ev;
+
+ if (!binary) {
+ is >> n;
+
+ // load pinyin table
+ for (i=0; i<n; i++) {
+ PinyinEntry entry (*m_validator, is, false);
+
+ if (!m_custom.use_tone) {
+ entry.set_key (PinyinKey (entry.get_key ().get_initial (),
+ entry.get_key ().get_final (),
+ SCIM_PINYIN_ZeroTone));
+ }
+
+ if (entry.get_key().get_final() == SCIM_PINYIN_ZeroFinal) {
+ std::cerr << "Invalid entry: " << entry << "\n";
+ } else {
+ if ((ev = find_exact_entry (entry)) == m_table.end())
+ m_table.push_back (entry);
+ else {
+ for (uint32 i=0; i<entry.size(); i++) {
+ ev->insert (entry.get_char_with_frequency_by_index (i));
+ }
+ }
+ }
+ }
+ } else {
+ unsigned char bytes [8];
+ is.read ((char*) bytes, sizeof (unsigned char) * 4);
+ n = scim_bytestouint32 (bytes);
+
+ // load pinyin table
+ for (i=0; i<n; i++) {
+ PinyinEntry entry (*m_validator, is, true);
+
+ if (!m_custom.use_tone) {
+ entry.set_key (PinyinKey (entry.get_key ().get_initial (),
+ entry.get_key ().get_final (),
+ SCIM_PINYIN_ZeroTone));
+ }
+
+ if (entry.get_key().get_final() == SCIM_PINYIN_ZeroFinal) {
+ std::cerr << "Invalid entry: " << entry << "\n";
+ } else {
+ if ((ev = find_exact_entry (entry)) == m_table.end())
+ m_table.push_back (entry);
+ else {
+ for (uint32 i=0; i<entry.size(); i++) {
+ ev->insert (entry.get_char_with_frequency_by_index (i));
+ }
+ }
+ }
+ }
+ }
+ sort ();
+ }
+ catch (std::ifstream::failure e) {
+ std::cerr << "Reading pinyin table failed" << std::endl;
return false;
-
- uint32 i;
- uint32 n;
- PinyinEntryVector::iterator ev;
-
- if (!binary) {
- is >> n;
-
- // load pinyin table
- for (i=0; i<n; i++) {
- PinyinEntry entry (*m_validator, is, false);
-
- if (!m_custom.use_tone) {
- entry.set_key (PinyinKey (entry.get_key ().get_initial (),
- entry.get_key ().get_final (),
- SCIM_PINYIN_ZeroTone));
- }
-
- if (entry.get_key().get_final() == SCIM_PINYIN_ZeroFinal) {
- std::cerr << "Invalid entry: " << entry << "\n";
- } else {
- if ((ev = find_exact_entry (entry)) == m_table.end())
- m_table.push_back (entry);
- else {
- for (uint32 i=0; i<entry.size(); i++) {
- ev->insert (entry.get_char_with_frequency_by_index (i));
- }
- }
- }
- }
- } else {
- unsigned char bytes [8];
- is.read ((char*) bytes, sizeof (unsigned char) * 4);
- n = scim_bytestouint32 (bytes);
-
- // load pinyin table
- for (i=0; i<n; i++) {
- PinyinEntry entry (*m_validator, is, true);
-
- if (!m_custom.use_tone) {
- entry.set_key (PinyinKey (entry.get_key ().get_initial (),
- entry.get_key ().get_final (),
- SCIM_PINYIN_ZeroTone));
- }
-
- if (entry.get_key().get_final() == SCIM_PINYIN_ZeroFinal) {
- std::cerr << "Invalid entry: " << entry << "\n";
- } else {
- if ((ev = find_exact_entry (entry)) == m_table.end())
- m_table.push_back (entry);
- else {
- for (uint32 i=0; i<entry.size(); i++) {
- ev->insert (entry.get_char_with_frequency_by_index (i));
- }
- }
- }
- }
}
- sort ();
return true;
}
scim-pinyin-0.5.91-save-in-temp.patch:
--- NEW FILE scim-pinyin-0.5.91-save-in-temp.patch ---
diff -up scim-pinyin-0.5.91/src/scim_pinyin_imengine.cpp.orig scim-pinyin-0.5.91/src/scim_pinyin_imengine.cpp
--- scim-pinyin-0.5.91/src/scim_pinyin_imengine.cpp.orig 2007-11-09 16:51:49.000000000 +0800
+++ scim-pinyin-0.5.91/src/scim_pinyin_imengine.cpp 2007-11-09 16:52:06.000000000 +0800
@@ -656,6 +656,11 @@ PinyinFactory::refresh ()
void
PinyinFactory::save_user_library ()
{
+ String tmp_user_pinyin_table = m_user_pinyin_table + ".tmp";
+ String tmp_user_phrase_lib = m_user_phrase_lib + ".tmp";
+ String tmp_user_pinyin_phrase_lib = m_user_pinyin_phrase_lib + ".tmp";
+ String tmp_user_pinyin_phrase_index = m_user_pinyin_phrase_index + ".tmp";
+
// First make the user data directory.
if (access (m_user_data_directory.c_str (), R_OK | W_OK) != 0) {
mkdir (m_user_data_directory.c_str (), S_IRUSR | S_IWUSR | S_IXUSR);
@@ -670,11 +675,23 @@ PinyinFactory::save_user_library ()
lib->optimize_phrase_frequencies ();
}
- m_pinyin_global.save_pinyin_table (m_user_pinyin_table.c_str (), m_user_data_binary);
- m_pinyin_global.save_user_phrase_lib (m_user_phrase_lib.c_str (),
- m_user_pinyin_phrase_lib.c_str (),
- m_user_pinyin_phrase_index.c_str (),
+ // save user data in tmp files
+ m_pinyin_global.save_pinyin_table (tmp_user_pinyin_table.c_str (), m_user_data_binary);
+ m_pinyin_global.save_user_phrase_lib (tmp_user_phrase_lib.c_str (),
+ tmp_user_pinyin_phrase_lib.c_str (),
+ tmp_user_pinyin_phrase_index.c_str (),
m_user_data_binary);
+
+ // unlink old user data files, and rename tmp files.
+ unlink (m_user_pinyin_table.c_str ());
+ rename (tmp_user_pinyin_table.c_str (), m_user_pinyin_table.c_str ());
+
+ unlink (m_user_phrase_lib.c_str ());
+ unlink (m_user_pinyin_phrase_lib.c_str ());
+ unlink (m_user_pinyin_phrase_index.c_str ());
+ rename (tmp_user_phrase_lib.c_str (), m_user_phrase_lib.c_str ());
+ rename (tmp_user_pinyin_phrase_lib.c_str (), m_user_pinyin_phrase_lib.c_str ());
+ rename (tmp_user_pinyin_phrase_index.c_str (), m_user_pinyin_phrase_index.c_str ());
}
void
Index: scim-pinyin.spec
===================================================================
RCS file: /cvs/pkgs/rpms/scim-pinyin/F-8/scim-pinyin.spec,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- scim-pinyin.spec 27 Aug 2007 03:39:06 -0000 1.41
+++ scim-pinyin.spec 15 Nov 2007 07:32:33 -0000 1.42
@@ -1,6 +1,6 @@
Name: scim-pinyin
Version: 0.5.91
-Release: 20%{?dist}
+Release: 22%{?dist}
Summary: Smart Pinyin IMEngine for Smart Common Input Method platform
License: GPLv2
@@ -16,6 +16,8 @@
Patch3: scim-pinyin-helper.patch
Patch4: scim-pinyin-0.5.91-13.bz200702.patch
Patch5: scim-pinyin-help-translate.patch
+Patch6: scim-pinyin-0.5.91-save-in-temp.patch
+Patch7: scim-pinyin-0.5.91-fix-load.patch
%description
Simplified Chinese Smart Pinyin IMEngine for SCIM.
@@ -27,6 +29,8 @@
%patch3 -p1 -b .3-helperi
%patch4 -p1 -b .4-bz200702
%patch5 -p1 -b .5-translate
+%patch6 -p1 -b .6-savetmp
+%patch7 -p1 -b .6-fix-load
%build
./bootstrap
@@ -60,6 +64,12 @@
%changelog
+* Thu Nov 15 2007 Huang Peng <phuang at redhat.com> - 0.5.91-22
+- Catch exception when load data from file to fix bug 237439.
+
+* Mon Nov 9 2007 Huang Peng <phuang at redhat.com> - 0.5.91-21
+- Save user data in temp files, and then overwrite old files to fix bug 237439.
+
* Mon Aug 27 2007 Huang Peng <phuang at redhat.com> - 0.5.91-20
- Change rpm license field to GPLv2
More information about the fedora-extras-commits
mailing list