SF.net SVN: geany:[5361] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Tue Nov 2 17:42:54 UTC 2010
Revision: 5361
http://geany.svn.sourceforge.net/geany/?rev=5361&view=rev
Author: ntrel
Date: 2010-11-02 17:42:54 +0000 (Tue, 02 Nov 2010)
Log Message:
-----------
Use g_file_replace_contents() if available to save documents - this
should help workaround bugs in GVFS.
Needs testing.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/document.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-11-02 17:39:46 UTC (rev 5360)
+++ trunk/ChangeLog 2010-11-02 17:42:54 UTC (rev 5361)
@@ -14,6 +14,10 @@
Go to Line dialog/field (patch by Dimitar Zhekov, thanks).
* src/main.c:
Print "GIO" and "built-in regex" if enabled with --version.
+ * src/document.c:
+ Use g_file_replace_contents() if available to save documents - this
+ should help workaround bugs in GVFS.
+ Needs testing.
2010-11-01 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c 2010-11-02 17:39:46 UTC (rev 5360)
+++ trunk/src/document.c 2010-11-02 17:42:54 UTC (rev 5361)
@@ -1704,24 +1704,29 @@
*data = conv_file_contents;
*len = conv_len;
}
-
return TRUE;
}
-static gchar *write_data_to_disk(GeanyDocument *doc, const gchar *locale_filename,
+static gchar *write_data_to_disk(const gchar *locale_filename,
const gchar *data, gint len)
{
+ GError *error = NULL;
+#ifdef HAVE_GIO
+ GFile *fp;
+
+ /* Use GIO API to save file (GVFS-safe) */
+ fp = g_file_new_for_path(locale_filename);
+ g_file_replace_contents(fp, data, len, NULL, FALSE,
+ G_FILE_CREATE_NONE, NULL, NULL, &error);
+#else
+ gint err = 0;
FILE *fp;
gint bytes_written;
- gint err = 0;
- GError *error = NULL;
- g_return_val_if_fail(doc != NULL, g_strdup(g_strerror(EINVAL)));
- g_return_val_if_fail(data != NULL, g_strdup(g_strerror(EINVAL)));
-
if (! file_prefs.use_safe_file_saving)
{
+ /* Use POSIX API for unsafe saving (GVFS-unsafe) */
fp = g_fopen(locale_filename, "wb");
if (G_UNLIKELY(fp == NULL))
return g_strdup(g_strerror(errno));
@@ -1738,15 +1743,32 @@
}
else
{
+ /* Use old GLib API for safe saving (GVFS-safe, but alters ownership and permissons) */
g_file_set_contents(locale_filename, data, len, &error);
- if (error != NULL)
- {
- gchar *msg = g_strdup(error->message);
- g_error_free(error);
- return msg;
- }
}
+#endif
+ if (error != NULL)
+ {
+ gchar *msg = g_strdup(error->message);
+ g_error_free(error);
+ return msg;
+ }
+ return NULL;
+}
+
+static gchar *save_doc(GeanyDocument *doc, const gchar *locale_filename,
+ const gchar *data, gint len)
+{
+ gchar *err;
+
+ g_return_val_if_fail(doc != NULL, g_strdup(g_strerror(EINVAL)));
+ g_return_val_if_fail(data != NULL, g_strdup(g_strerror(EINVAL)));
+
+ err = write_data_to_disk(locale_filename, data, len);
+ if (err)
+ return err;
+
/* now the file is on disk, set real_path */
if (doc->real_path == NULL)
{
@@ -1754,7 +1776,6 @@
doc->priv->is_remote = utils_is_remote_path(locale_filename);
monitor_file_setup(doc);
}
-
return NULL;
}
@@ -1849,7 +1870,7 @@
doc->priv->file_disk_status = FILE_IGNORE;
/* actually write the content of data to the file on disk */
- errmsg = write_data_to_disk(doc, locale_filename, data, len);
+ errmsg = save_doc(doc, locale_filename, data, len);
g_free(data);
if (errmsg != NULL)
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