SF.net SVN: geany:[3494] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Wed Jan 21 15:50:12 UTC 2009


Revision: 3494
          http://geany.svn.sourceforge.net/geany/?rev=3494&view=rev
Author:   eht16
Date:     2009-01-21 15:50:12 +0000 (Wed, 21 Jan 2009)

Log Message:
-----------
Reuse the locale-encoded filename in document_save_file().

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/document.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-01-21 09:26:13 UTC (rev 3493)
+++ trunk/ChangeLog	2009-01-21 15:50:12 UTC (rev 3494)
@@ -1,3 +1,9 @@
+2009-01-21  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
+
+ * src/document.c:
+   Reuse the locale-encoded filename in document_save_file().
+
+
 2009-01-20  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
 
  * src/treeviews.c:

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2009-01-21 09:26:13 UTC (rev 3493)
+++ trunk/src/document.c	2009-01-21 15:50:12 UTC (rev 3494)
@@ -1347,25 +1347,23 @@
 }
 
 
-static gboolean document_update_timestamp(GeanyDocument *doc)
+static gboolean document_update_timestamp(GeanyDocument *doc, const gchar *locale_filename)
 {
 #ifndef HAVE_GIO
 	struct stat st;
-	gchar *locale_filename;
 
 	g_return_val_if_fail(doc != NULL, FALSE);
 
-	locale_filename = utils_get_locale_from_utf8(doc->file_name);
+	/* stat the file to get the timestamp, otherwise on Windows the actual
+	 * timestamp can be ahead of time(NULL) */
 	if (g_stat(locale_filename, &st) != 0)
 	{
 		ui_set_statusbar(TRUE, _("Could not open file %s (%s)"), doc->file_name,
 			g_strerror(errno));
-		g_free(locale_filename);
 		return FALSE;
 	}
 
 	doc->priv->mtime = st.st_mtime; /* get the modification time from file and keep it */
-	g_free(locale_filename);
 #endif
 	return TRUE;
 }
@@ -1565,22 +1563,18 @@
 }
 
 
-static gint write_data_to_disk(GeanyDocument *doc, const gchar *data, gint len)
+static gint write_data_to_disk(GeanyDocument *doc, const gchar *locale_filename,
+							   const gchar *data, gint len)
 {
 	FILE *fp;
 	gint bytes_written;
-	gchar *locale_filename = NULL;
 	gint err = 0;
 
 	g_return_val_if_fail(data != NULL, EINVAL);
 
-	locale_filename = utils_get_locale_from_utf8(doc->file_name);
 	fp = g_fopen(locale_filename, "wb");
 	if (fp == NULL)
-	{
-		g_free(locale_filename);
 		return errno;
-	}
 
 	bytes_written = fwrite(data, sizeof(gchar), len, fp);
 
@@ -1595,7 +1589,6 @@
 		doc->real_path = tm_get_real_path(locale_filename);
 		doc->priv->is_remote = utils_is_remote_path(locale_filename);
 	}
-	g_free(locale_filename);
 
 	return err;
 }
@@ -1619,6 +1612,7 @@
 	gchar *data;
 	gsize len;
 	gint err;
+	gchar *locale_filename;
 
 	if (doc == NULL)
 		return FALSE;
@@ -1677,8 +1671,10 @@
 		len = strlen(data);
 	}
 
+	locale_filename = utils_get_locale_from_utf8(doc->file_name);
+
 	/* actually write the content of data to the file on disk */
-	err = write_data_to_disk(doc, data, len);
+	err = write_data_to_disk(doc, locale_filename, data, len);
 	g_free(data);
 
 	/* ignore file changed notification after writing the file */
@@ -1690,6 +1686,7 @@
 		dialogs_show_msgbox_with_secondary(GTK_MESSAGE_ERROR,
 			_("Error saving file."), g_strerror(err));
 		utils_beep();
+		g_free(locale_filename);
 		return FALSE;
 	}
 
@@ -1701,10 +1698,8 @@
 	{
 		sci_set_savepoint(doc->editor->sci);
 
-		/* stat the file to get the timestamp, otherwise on Windows the actual
-		 * timestamp can be ahead of time(NULL) */
 		if (file_prefs.disk_check_timeout > 0)
-			document_update_timestamp(doc);
+			document_update_timestamp(doc, locale_filename);
 
 		/* update filetype-related things */
 		document_set_filetype(doc, doc->file_type);
@@ -1719,6 +1714,8 @@
 		vte_cwd(doc->file_name, FALSE);
 #endif
 	}
+	g_free(locale_filename);
+
 	g_signal_emit_by_name(geany_object, "document-save", doc);
 
 	return TRUE;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list