// Reload config to ensure user made modification won't lost.
load_all_config ();
+ if (!scim_is_symlink(userconf.c_str ())) return false;
+
std::ofstream os (userconf.c_str ());
if (!os) return false;
SCIM_DEBUG_IMENGINE(1) << "Creating temporary icon file: " << tempfile << "\n";
- std::ofstream os (tempfile.c_str ());
-
- if (os) {
- os.write (bufptr, (std::streamsize)filesize);
- os.close ();
-
- // Check if the file is written correctly.
- if (scim_load_file (tempfile, 0) == filesize) {
- m_icon_repository [icon] = tempfile;
- local_icon = tempfile;
- } else {
- unlink (tempfile.c_str ());
+ if (!scim_is_symlink(tempfile.c_str ())) {
+ std::ofstream os (tempfile.c_str ());
+
+ if (os) {
+ os.write (bufptr, (std::streamsize)filesize);
+ os.close ();
+
+ // Check if the file is written correctly.
+ if (scim_load_file (tempfile, 0) == filesize) {
+ m_icon_repository [icon] = tempfile;
+ local_icon = tempfile;
+ } else {
+ unlink (tempfile.c_str ());
+ }
}
}
}
__config_repository.usr.erase (it->first);
}
- std::ofstream usr_os (usr_conf_file.c_str ());
+ if (!scim_is_symlink(usr_conf_file.c_str ())) {
+ std::ofstream usr_os (usr_conf_file.c_str ());
- if (usr_os) {
- for (KeyValueRepository::iterator it = __config_repository.usr.begin ();
- it != __config_repository.usr.end (); ++it) {
- usr_os << it->first << " = " << it->second << "\n";
- }
- __config_repository.updated.clear ();
+ if (usr_os) {
+ for (KeyValueRepository::iterator it = __config_repository.usr.begin ();
+ it != __config_repository.usr.end (); ++it) {
+ usr_os << it->first << " = " << it->second << "\n";
+ }
+ __config_repository.updated.clear ();
- sync();
+ sync();
- return true;
+ return true;
+ }
}
return false;
String strLogFile = scim_get_user_data_dir () + String (SCIM_PATH_DELIM_STRING) + String ("isf.log");
int ret = stat(strLogFile.c_str(), &st);
if (ret == 0 || (ret == -1 && errno == ENOENT)) {
- if (st.st_size < MAX_LOG_FILE_SIZE) {
+ if (st.st_size < MAX_LOG_FILE_SIZE && !scim_is_symlink(strLogFile.c_str ())) {
std::ofstream isf_log_file (strLogFile.c_str (), std::ios::app);
isf_log_file << buf << std::endl;
isf_log_file.flush ();
LOGD ("%s", buf);
}
+EXAPI bool scim_is_symlink (const String filename)
+{
+ struct stat info;
+ if (lstat(filename.c_str (), &info) < 0) {
+ char buf_err[256];
+ LOGE("lstat failed. %s", strerror_r (errno, buf_err, sizeof (buf_err)));
+ return false;
+ }
+
+ return S_ISLNK(info.st_mode);
+}
+
static struct timeval _t0 = {0, 0};
static struct timeval _t1;
*/
EXAPI void isf_save_log (const char *fmt, ...);
+/**
+ * @brief Check whether the given file is symbolic link or not.
+ *
+ * @return true if the file is a symbolic link.
+ */
+EXAPI bool scim_is_symlink (const String filename);
+
#define ISF_SAVE_LOG(fmt, arg...) \
do{ \
isf_save_log ("time:%ld pid:%d %s %s " fmt, time (0), getpid (), __FILE__, __func__, ##arg); \