libgnome r3588 - in trunk: . libgnome



Author: kmaraas
Date: Thu Jan 17 13:04:41 2008
New Revision: 3588
URL: http://svn.gnome.org/viewvc/libgnome?rev=3588&view=rev

Log:
2008-01-17  Kjartan Maraas  <kmaraas gnome org>

	* libgnome/gnome-config.c: (dump_keys), (dump_sections),
	(dump_sections_to_file), (dump_profile): Make this more
	robust against full disk situations. Patch from edpeur at gmail com
	Closes bug #507687.
	* libgnome/libgnome-2.0.pc.in: Add localstatedir variable so
	we can tell where gnome-games should look for highscore files.
	Closes some bug I can't find :-/

Modified:
   trunk/ChangeLog
   trunk/libgnome/gnome-config.c
   trunk/libgnome/libgnome-2.0.pc.in

Modified: trunk/libgnome/gnome-config.c
==============================================================================
--- trunk/libgnome/gnome-config.c	(original)
+++ trunk/libgnome/gnome-config.c	Thu Jan 17 13:04:41 2008
@@ -622,26 +622,26 @@
 }
 
 static void
-dump_keys (FILE *profile, TKeys *p)
+dump_keys (GString *profile, TKeys *p)
 {
 	if (!p)
 		return;
 	dump_keys (profile, p->link);
 	if (*p->key_name) {
 		char *t = escape_string_and_dup (p->value);
-		fprintf (profile, "%s=%s\n", p->key_name, t);
+		g_string_append_printf (profile, "%s=%s\n", p->key_name, t);
 		g_free (t);
 	}
 }
 
 static void
-dump_sections (FILE *profile, TSecHeader *p)
+dump_sections (GString *profile, TSecHeader *p)
 {
 	if (!p)
 		return;
 	dump_sections (profile, p->link);
 	if (p->section_name && p->section_name [0]){
-		fprintf (profile, "\n[%s]\n", p->section_name);
+		g_string_append_printf (profile, "\n[%s]\n", p->section_name);
 		dump_keys (profile, p->keys);
 	}
 }
@@ -729,12 +729,32 @@
 }
 
 
+static gboolean
+dump_sections_to_file (TProfile *p)
+{
+	GError *err = NULL;
+	GString *profile = g_string_new("");
+
+	dump_sections (profile, p->section);
+
+	g_file_set_contents(p->filename, profile->str, profile->len, &err);
+
+	g_string_free(profile,TRUE);
+
+	if (err != NULL) {
+		/* TODO Maybe the error should be displayed */
+		g_error_free (err);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
 
 static gboolean
 dump_profile (TProfile *p, gboolean one_only)
 {
 	gboolean ret = TRUE;
-	FILE *profile;
 
 	if (!p)
 		return ret;
@@ -771,9 +791,8 @@
 			if(p==Current)
 				Current = NULL;
 		} else if (check_path(p->filename,0755) &&
-		    (profile = g_fopen (p->filename, "w")) != NULL){
-			dump_sections (profile, p->section);
-			fclose (profile);
+			dump_sections_to_file(p)){
+			/* File written correctly */
 		} else {
 			/* we failed at actually writing to the file */
 			ret = FALSE;

Modified: trunk/libgnome/libgnome-2.0.pc.in
==============================================================================
--- trunk/libgnome/libgnome-2.0.pc.in	(original)
+++ trunk/libgnome/libgnome-2.0.pc.in	Thu Jan 17 13:04:41 2008
@@ -3,6 +3,7 @@
 libdir= libdir@
 includedir= includedir@
 libgnome_serverdir= libexecdir@
+localstatedir= localstatedir@
 
 Name: libgnome
 Description: libgnome



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]