[uim-commit] r1164 - trunk/uim

tkng at freedesktop.org tkng at freedesktop.org
Tue Aug 9 09:52:41 EST 2005


Author: tkng
Date: 2005-08-08 16:52:37 -0700 (Mon, 08 Aug 2005)
New Revision: 1164

Modified:
   trunk/uim/uim-custom.c
Log:
* uim/uim-custom.c: This commit aims to stop saving config file if nothing
  changed. As a result, we'll be able to avoid needless reloading of config files.
 -(file_content_is_same): New internal function.
 -(uim_custom_save_group): Don't change mtime of the file if nothing has 
   been changed.


Modified: trunk/uim/uim-custom.c
===================================================================
--- trunk/uim/uim-custom.c	2005-08-08 21:37:42 UTC (rev 1163)
+++ trunk/uim/uim-custom.c	2005-08-08 23:52:37 UTC (rev 1164)
@@ -829,7 +829,35 @@
   return for_each_primary_groups(uim_custom_load_group);
 }
 
+
 static uim_bool
+file_content_is_same(const char *a_path, const char *b_path)
+{
+  FILE *a, *b;
+  char a_buf[4096], b_buf[4096];
+
+  a = fopen(a_path, "r");
+  b = fopen(b_path, "r");
+
+  while(1) {
+    char *a_eof, *b_eof;
+    a_eof = fgets(a_buf, sizeof(a_buf), a);
+    b_eof = fgets(b_buf, sizeof(b_buf), b);
+
+    if(!a_eof && !b_eof)
+      break;
+    if((!a_eof && b_eof) || (a_eof && !b_eof))
+      return UIM_FALSE;
+
+    if(strcmp(a_buf, b_buf) != 0)
+      return UIM_FALSE;
+  }
+
+  return UIM_TRUE;
+}
+
+
+static uim_bool
 uim_custom_save_group(const char *group)
 {
   uim_bool succeeded = UIM_FALSE;
@@ -869,9 +897,16 @@
   if (fclose(file) < 0)
     goto error;
   /* rename prepared temporary file to proper name */
+
   file_path = custom_file_path(group, 0);
-  succeeded = (rename(tmp_file_path, file_path) == 0);
+  if(file_content_is_same(tmp_file_path, file_path)) {
+    succeeded = UIM_TRUE;
+    remove(tmp_file_path);
+  } else {
+    succeeded = (rename(tmp_file_path, file_path) == 0);
+  }
   free(file_path);
+
  error:
   free(tmp_file_path);
 



More information about the uim-commit mailing list