[Kazehakase-cvs] kazehakase-svn [3060] * src/utils/utils.c ( kz_utils_purge_files_by_time_stamp): fixed a

Back to archive index

svnno****@sourc***** svnno****@sourc*****
Tue Mar 27 20:26:13 JST 2007


Revision: 3060
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=3060
Author:   kous
Date:     2007-03-27 20:26:13 +0900 (Tue, 27 Mar 2007)

Log Message:
-----------
* src/utils/utils.c (kz_utils_purge_files_by_time_stamp): fixed a
bug that time-stamp is always deleted.
* src/utils/utils.[ch] (kz_utils_cp): added.

Modified Paths:
--------------
    kazehakase/trunk/ChangeLog
    kazehakase/trunk/src/utils/utils.c
    kazehakase/trunk/src/utils/utils.h

Modified: kazehakase/trunk/ChangeLog
===================================================================
--- kazehakase/trunk/ChangeLog	2007-03-27 10:42:45 UTC (rev 3059)
+++ kazehakase/trunk/ChangeLog	2007-03-27 11:26:13 UTC (rev 3060)
@@ -1,5 +1,10 @@
 2007-03-27  Kouhei Sutou  <kou****@cozmi*****>
 
+	* src/utils/utils.c (kz_utils_purge_files_by_time_stamp): fixed a
+	bug that time-stamp is always deleted.
+
+	* src/utils/utils.[ch] (kz_utils_cp): added.
+
 	* src/kz-app.c (kz_app_set_search): supported NULL as remove
 	search engine.
 

Modified: kazehakase/trunk/src/utils/utils.c
===================================================================
--- kazehakase/trunk/src/utils/utils.c	2007-03-27 10:42:45 UTC (rev 3059)
+++ kazehakase/trunk/src/utils/utils.c	2007-03-27 11:26:13 UTC (rev 3060)
@@ -44,6 +44,33 @@
 #define TIME_STAMP_FORMAT "%ld,%s\n"
 
 gboolean
+kz_utils_cp (const gchar *from, const gchar *to)
+{
+	FILE *fp;
+	gboolean success = FALSE;
+	gchar *contents;
+	gsize length;
+
+	if (!g_file_get_contents(from, &contents, &length, NULL))
+		return FALSE;
+
+	fp = g_fopen(to, "wb");
+	if (fp)
+	{
+		success = TRUE;
+		if (fwrite(contents, length, 1, fp) != 1)
+			success = FALSE;
+		fclose(fp);
+
+		if (!success)
+			g_unlink(to);
+	}
+
+	g_free(contents);
+	return success;
+}
+
+gboolean
 key_seems_sequential (const gchar *key, const gchar *prefix)
 {
 	gint len;
@@ -680,7 +707,8 @@
 	fclose(fp);
 
 	g_unlink(time_stamp_path);
-	g_rename(tmp_file, time_stamp_path);
+	kz_utils_cp(tmp_file, time_stamp_path);
+	g_unlink(tmp_file);
 }
 
 gchar *

Modified: kazehakase/trunk/src/utils/utils.h
===================================================================
--- kazehakase/trunk/src/utils/utils.h	2007-03-27 10:42:45 UTC (rev 3059)
+++ kazehakase/trunk/src/utils/utils.h	2007-03-27 11:26:13 UTC (rev 3060)
@@ -28,6 +28,9 @@
 
 G_BEGIN_DECLS
 
+gboolean kz_utils_cp			(const gchar *from,
+					 const gchar *to);
+
 gboolean key_seems_sequential        (const gchar *key,
 				      const gchar *prefix);
 gchar   *remove_tag                  (const gchar *string, gsize len);




More information about the Kazehakase-cvs mailing list
Back to archive index