[Xfce4-commits] <gigolo:master> resolve symbolic links before writing config files

Enrico Tröger noreply at xfce.org
Sun Oct 17 10:54:01 CEST 2010


Updating branch refs/heads/master
         to 32eab35513a4023bdfd5792fb6f1a4af3b3c701b (commit)
       from 36cee9c2b37275634b6137ee1143fd2074217b14 (commit)

commit 32eab35513a4023bdfd5792fb6f1a4af3b3c701b
Author: Enrico Tröger <enrico at xfce.org>
Date:   Sat Oct 16 16:49:47 2010 +0200

    resolve symbolic links before writing config files

 src/settings.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/src/settings.c b/src/settings.c
index dece5d3..e46ce3c 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -380,6 +380,7 @@ static void write_data(GKeyFile *k, const gchar *filename)
 	gsize len;
 	GError *error = NULL;
 	gchar *data;
+	gchar *real_filename;
 
 	data = g_key_file_to_data(k, &len, &error);
 	if (data == NULL || error != NULL)
@@ -389,13 +390,31 @@ static void write_data(GKeyFile *k, const gchar *filename)
 		g_free(data);
 		return;
 	}
+	/* resolve symbolic links */
+	if (g_file_test(filename, G_FILE_TEST_IS_SYMLINK))
+	{
+		real_filename = g_file_read_link(filename, &error);
+		if (error)
+		{
+			g_warning("Writing configuration file to disk failed (%s).", error->message);
+			g_error_free(error);
+			g_free(data);
+			return;
+		}
+	}
+	else
+	{
+		real_filename = g_strdup(filename);
+	}
 
-	if (! g_file_set_contents(filename, data, len, &error))
+	/* write data to file */
+	if (! g_file_set_contents(real_filename, data, len, &error))
 	{
 		g_warning("Writing configuration file to disk failed (%s).", error->message);
 		g_error_free(error);
 	}
 	g_free(data);
+	g_free(real_filename);
 }
 
 



More information about the Xfce4-commits mailing list