Revision: 3722
http://geany.svn.sourceforge.net/geany/?rev=3722&view=rev
Author: eht16
Date: 2009-04-21 20:54:04 +0000 (Tue, 21 Apr 2009)
Log Message:
-----------
Add a hidden preference 'use_safe_file_saving' to save files to disk by creating a temporary file first. This has serious side effects, please read the documentation before enabling this.
Modified Paths:
--------------
trunk/ChangeLog
trunk/doc/geany.html
trunk/doc/geany.txt
trunk/src/document.c
trunk/src/document.h
trunk/src/keyfile.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-04-21 20:53:42 UTC (rev 3721)
+++ trunk/ChangeLog 2009-04-21 20:54:04 UTC (rev 3722)
@@ -9,6 +9,11 @@
document_get_basename_for_display() to the plugin API.
* doc/geany.html, doc/geany.txt, src/toolbar.c:
Add new toolbar element: Print (patch by Roland Baudin, thanks).
+ * doc/geany.html, doc/geany.txt, src/document.c, src/document.h,
+ src/keyfile.c:
+ Add a hidden preference 'use_safe_file_saving' to save files to disk
+ by creating a temporary file first. This has serious side effects,
+ please read the documentation before enabling this.
2009-04-20 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/doc/geany.html
===================================================================
--- trunk/doc/geany.html 2009-04-21 20:53:42 UTC (rev 3721)
+++ trunk/doc/geany.html 2009-04-21 20:54:04 UTC (rev 3722)
@@ -4221,6 +4221,30 @@
<tt class="docutils literal"><span class="pre">vte/termcap/xterm</span></tt>.</td>
<td>xterm</td>
</tr>
+<tr><td><strong>File related</strong></td>
+<td> </td>
+<td> </td>
+</tr>
+<tr><td>use_safe_file_saving</td>
+<td>Defines the mode how Geany saves files to
+disk. If disabled, Geany directly writes
+the content of the document to disk. This
+might cause in loss of data when there is
+no more free space on disk to save the
+file. When set to true, Geany first saves
+the contents into a temporary file and if
+this succeeded, the temporary file is
+moved to the real file to save.
+This gives better error checking in case of
+no more free disk space. But it also
+destroys hard links of the original file
+and its permissions (e.g. executable flags
+are reset). Use this with care as it can
+break things seriously.
+The better approach would be to ensure your
+disk won't run out of free space.</td>
+<td>false</td>
+</tr>
</tbody>
</table>
</div>
@@ -4792,7 +4816,7 @@
<div class="footer">
<hr class="footer" />
<a class="reference external" href="geany.txt">View document source</a>.
-Generated on: 2009-04-21 19:06 UTC.
+Generated on: 2009-04-21 19:30 UTC.
Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
</div>
Modified: trunk/doc/geany.txt
===================================================================
--- trunk/doc/geany.txt 2009-04-21 20:53:42 UTC (rev 3721)
+++ trunk/doc/geany.txt 2009-04-21 20:54:04 UTC (rev 3722)
@@ -3704,6 +3704,24 @@
emulation Terminal emulation mode. Only change this xterm
if you have VTE termcap files other than
``vte/termcap/xterm``.
+**File related**
+use_safe_file_saving Defines the mode how Geany saves files to false
+ disk. If disabled, Geany directly writes
+ the content of the document to disk. This
+ might cause in loss of data when there is
+ no more free space on disk to save the
+ file. When set to true, Geany first saves
+ the contents into a temporary file and if
+ this succeeded, the temporary file is
+ moved to the real file to save.
+ This gives better error checking in case of
+ no more free disk space. But it also
+ destroys hard links of the original file
+ and its permissions (e.g. executable flags
+ are reset). Use this with care as it can
+ break things seriously.
+ The better approach would be to ensure your
+ disk won't run out of free space.
================================ =========================================== ==================
Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c 2009-04-21 20:53:42 UTC (rev 3721)
+++ trunk/src/document.c 2009-04-21 20:54:04 UTC (rev 3722)
@@ -1680,34 +1680,55 @@
}
-static gint write_data_to_disk(GeanyDocument *doc, const gchar *locale_filename,
- const gchar *data, gint len)
+static gchar *write_data_to_disk(GeanyDocument *doc, const gchar *locale_filename,
+ const gchar *data, gint len)
{
FILE *fp;
gint bytes_written;
gint err = 0;
+ GError *error = NULL;
- g_return_val_if_fail(data != NULL, EINVAL);
+ g_return_val_if_fail(doc != NULL, g_strdup(g_strerror(EINVAL)));
+ g_return_val_if_fail(data != NULL, g_strdup(g_strerror(EINVAL)));
- fp = g_fopen(locale_filename, "wb");
- if (G_UNLIKELY(fp == NULL))
- return errno;
+ /* we never use g_file_set_contents() for remote files as Geany only writes such files
+ * 'into' the Fuse mountpoint, the file itself is then written by GVfs on the target
+ * remote filesystem. */
+ if (! file_prefs.use_safe_file_saving || doc->priv->is_remote)
+ {
+ fp = g_fopen(locale_filename, "wb");
+ if (G_UNLIKELY(fp == NULL))
+ return g_strdup(g_strerror(errno));
- bytes_written = fwrite(data, sizeof(gchar), len, fp);
+ bytes_written = fwrite(data, sizeof(gchar), len, fp);
- if (G_UNLIKELY(len != bytes_written))
- err = errno;
+ if (G_UNLIKELY(len != bytes_written))
+ err = errno;
- fclose(fp);
+ fclose(fp);
+ if (err != 0)
+ return g_strdup(g_strerror(err));
+ }
+ else
+ {
+ g_file_set_contents(locale_filename, data, len, &error);
+ if (error != NULL)
+ {
+ gchar *msg = g_strdup(error->message);
+ g_error_free(error);
+ return msg;
+ }
+ }
+
/* now the file is on disk, set real_path */
- if (err == 0 && doc->real_path == NULL)
+ if (doc->real_path == NULL)
{
doc->real_path = tm_get_real_path(locale_filename);
doc->priv->is_remote = utils_is_remote_path(locale_filename);
}
- return err;
+ return NULL;
}
@@ -1726,9 +1747,9 @@
**/
gboolean document_save_file(GeanyDocument *doc, gboolean force)
{
+ gchar *errmsg;
gchar *data;
gsize len;
- gint err;
gchar *locale_filename;
g_return_val_if_fail(doc != NULL, FALSE);
@@ -1793,17 +1814,17 @@
doc->priv->file_disk_status = FILE_IGNORE;
/* actually write the content of data to the file on disk */
- err = write_data_to_disk(doc, locale_filename, data, len);
+ errmsg = write_data_to_disk(doc, locale_filename, data, len);
g_free(data);
- if (G_UNLIKELY(err != 0))
+ if (errmsg != NULL)
{
- ui_set_statusbar(TRUE, _("Error saving file (%s)."), g_strerror(err));
- dialogs_show_msgbox_with_secondary(GTK_MESSAGE_ERROR,
- _("Error saving file."), g_strerror(err));
+ ui_set_statusbar(TRUE, _("Error saving file (%s)."), errmsg);
+ dialogs_show_msgbox_with_secondary(GTK_MESSAGE_ERROR, _("Error saving file."), errmsg);
doc->priv->file_disk_status = FILE_OK;
utils_beep();
g_free(locale_filename);
+ g_free(errmsg);
return FALSE;
}
Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h 2009-04-21 20:53:42 UTC (rev 3721)
+++ trunk/src/document.h 2009-04-21 20:54:04 UTC (rev 3722)
@@ -56,6 +56,7 @@
gint default_eol_character;
gint disk_check_timeout;
gboolean cmdline_new_files; /* New file if command-line filename doesn't exist */
+ gboolean use_safe_file_saving;
}
GeanyFilePrefs;
Modified: trunk/src/keyfile.c
===================================================================
--- trunk/src/keyfile.c 2009-04-21 20:53:42 UTC (rev 3721)
+++ trunk/src/keyfile.c 2009-04-21 20:54:04 UTC (rev 3722)
@@ -172,6 +172,8 @@
"show_symbol_list_expanders", TRUE);
stash_group_add_boolean(group, &ui_prefs.allow_always_save,
"allow_always_save", FALSE);
+ stash_group_add_boolean(group, &file_prefs.use_safe_file_saving,
+ "use_safe_file_saving", FALSE);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3721
http://geany.svn.sourceforge.net/geany/?rev=3721&view=rev
Author: eht16
Date: 2009-04-21 20:53:42 +0000 (Tue, 21 Apr 2009)
Log Message:
-----------
Add new toolbar element: Print (patch by Roland Baudin, thanks).
Modified Paths:
--------------
trunk/ChangeLog
trunk/doc/geany.html
trunk/doc/geany.txt
trunk/src/toolbar.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-04-21 20:53:23 UTC (rev 3720)
+++ trunk/ChangeLog 2009-04-21 20:53:42 UTC (rev 3721)
@@ -7,6 +7,8 @@
* src/plugins.c, src/plugindata.h, plugins/geanyfunctions.h:
Add utils_str_middle_truncate() and
document_get_basename_for_display() to the plugin API.
+ * doc/geany.html, doc/geany.txt, src/toolbar.c:
+ Add new toolbar element: Print (patch by Roland Baudin, thanks).
2009-04-20 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/doc/geany.html
===================================================================
--- trunk/doc/geany.html 2009-04-21 20:53:23 UTC (rev 3720)
+++ trunk/doc/geany.html 2009-04-21 20:53:42 UTC (rev 3721)
@@ -6,7 +6,7 @@
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
<title>Geany</title>
<meta name="authors" content="Enrico Tröger Nick Treleaven Frank Lanitz" />
-<meta name="date" content="2009-03-31" />
+<meta name="date" content="$Date$" />
<style type="text/css">
/*
@@ -139,7 +139,7 @@
<br />Nick Treleaven
<br />Frank Lanitz</td></tr>
<tr><th class="docinfo-name">Date:</th>
-<td>2009-03-31</td></tr>
+<td>$Date$</td></tr>
<tr><th class="docinfo-name">Version:</th>
<td>0.17</td></tr>
</tbody>
@@ -3834,8 +3834,8 @@
<p>Then edit it and add any of the available elements listed in the file or remove
any of the existing elements. Of course, you can also reorder the elements as
you wish and add or remove additional separators.
-This file must be valid XML unless it can't be loaded and the global toolbar
-UI definition is used.</p>
+This file must be valid XML, otherwise the global toolbar UI definition
+will be used instead.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<ol class="last arabic simple">
@@ -3879,6 +3879,9 @@
<tr><td>CloseAll</td>
<td>Close all open files</td>
</tr>
+<tr><td>Print</td>
+<td>Print the current file</td>
+</tr>
<tr><td>Cut</td>
<td>Cut the current selection</td>
</tr>
@@ -3940,7 +3943,7 @@
<td>The goto field belonging to the 'Goto' element (can be used alone)</td>
</tr>
<tr><td>Goto</td>
-<td>Jump to the entered line number (only useful if you also use 'SearchEntry')</td>
+<td>Jump to the entered line number (only useful if you also use 'GotoEntry')</td>
</tr>
<tr><td>Preferences</td>
<td>Show the preferences dialog</td>
@@ -4789,7 +4792,7 @@
<div class="footer">
<hr class="footer" />
<a class="reference external" href="geany.txt">View document source</a>.
-Generated on: 2009-04-05 15:09 UTC.
+Generated on: 2009-04-21 19:06 UTC.
Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
</div>
Modified: trunk/doc/geany.txt
===================================================================
--- trunk/doc/geany.txt 2009-04-21 20:53:23 UTC (rev 3720)
+++ trunk/doc/geany.txt 2009-04-21 20:53:42 UTC (rev 3721)
@@ -3476,6 +3476,7 @@
Reload Reload the current file from disk
Close Close the current file
CloseAll Close all open files
+Print Print the current file
Cut Cut the current selection
Copy Copy the current selection
Paste Paste the contents of the clipboard
Modified: trunk/src/toolbar.c
===================================================================
--- trunk/src/toolbar.c 2009-04-21 20:53:23 UTC (rev 3720)
+++ trunk/src/toolbar.c 2009-04-21 20:53:42 UTC (rev 3721)
@@ -72,6 +72,7 @@
{ "Goto", GTK_STOCK_JUMP_TO, NULL, NULL, N_("Jump to the entered line number"), G_CALLBACK(on_toolbutton_goto_clicked) },
{ "Preferences", GTK_STOCK_PREFERENCES, NULL, NULL, N_("Show the preferences dialog"), G_CALLBACK(on_toolbutton_preferences_clicked) },
{ "Quit", GTK_STOCK_QUIT, NULL, NULL, N_("Quit Geany"), G_CALLBACK(on_toolbutton_quit_clicked) },
+ { "Print", GTK_STOCK_PRINT, NULL, NULL, N_("Print document"), G_CALLBACK(on_print1_activate) }
};
const guint ui_entries_n = G_N_ELEMENTS(ui_entries);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.