]> www.fi.muni.cz Git - evince.git/commitdiff
Do Save a copy in atomic way. Fixes bug #328266.
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sat, 13 Jan 2007 13:16:13 +0000 (13:16 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Sat, 13 Jan 2007 13:16:13 +0000 (13:16 +0000)
2007-01-13  Carlos Garcia Campos  <carlosgc@gnome.org>
* shell/ev-window.c: (file_save_dialog_response_cb):
Do Save a copy in atomic way. Fixes bug #328266.

svn path=/trunk/; revision=2221

ChangeLog
shell/ev-window.c

index c64ddd119ca9c0d89c6d2debee36c7bb3d46a7bd..2f0bf6128a74b6e16b9e3beae9f7beb5bdbf23b0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-01-13  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-window.c: (file_save_dialog_response_cb):
+
+       Do Save a copy in atomic way. Fixes bug #328266. 
+
 2007-01-12  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-sidebar-links.c: (update_page_callback_foreach):
index ba8de920e667def9a030dd6482e2c1bdb67a6467..07080e74fe876f793566fcde3110bae3d9f5e280 100644 (file)
@@ -1585,23 +1585,59 @@ file_save_dialog_response_cb (GtkWidget *fc,
        gboolean success;
 
        if (response_id == GTK_RESPONSE_OK) {
-               gchar *uri;
-               GError *err = NULL;
+               gint    fd;
+               gchar  *filename;
+               gchar  *tmp_filename;
+               GError *error = NULL;
 
-               uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
+               filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fc));
+               tmp_filename = g_strdup_printf ("%s.XXXXXX", filename);
+               
+               fd = g_mkstemp (tmp_filename);
+               if (fd == -1) {
+                       gchar  *display_name;
+                       gint    save_errno = errno;
+                       
+                       display_name = g_filename_display_name (tmp_filename);
+                       g_set_error (&error,
+                                    G_FILE_ERROR,
+                                    g_file_error_from_errno (save_errno),
+                                    _("Failed to create file ā€œ%sā€: %s"),
+                                    display_name, g_strerror (save_errno));
+                       g_free (display_name);
+               } else {
+                       gchar *uri;
+
+                       uri = g_filename_to_uri (tmp_filename, NULL, NULL);
+                       
+                       ev_document_doc_mutex_lock ();
+                       success = ev_document_save (ev_window->priv->document,
+                                                   uri,
+                                                   &error);
+                       ev_document_doc_mutex_unlock ();
 
-               ev_document_doc_mutex_lock ();
-               success = ev_document_save (ev_window->priv->document, uri, &err);
-               ev_document_doc_mutex_unlock ();
+                       g_free (uri);
+                       close (fd);
+               }
 
-               if (err) {
+               if (!error) {
+                       if (g_rename (tmp_filename, filename) == -1) {
+                               g_unlink (tmp_filename);
+                       }
+               } else {
                        gchar *msg;
+                       gchar *uri;
+
+                       uri = g_filename_to_uri (filename, NULL, NULL);
                        msg = g_strdup_printf (_("The file could not be saved as ā€œ%sā€."), uri);
-                       ev_window_error_dialog (GTK_WINDOW (fc), msg, err);
+                       ev_window_error_dialog (GTK_WINDOW (ev_window), msg, error);
                        g_free (msg);
+                       g_free (uri);
+                       g_error_free (error);
                }
-
-               g_free (uri);
+               
+               g_free (tmp_filename);
+               g_free (filename);
        }
 
        gtk_widget_destroy (fc);
@@ -4317,7 +4353,7 @@ image_save_dialog_response_cb (GtkWidget *fc,
                         filename, "png", &error, NULL);
        
        if (error) {
-               ev_window_error_dialog (GTK_WINDOW (fc),
+               ev_window_error_dialog (GTK_WINDOW (ev_window),
                                        _("The image could not be saved."),
                                        error);
                g_error_free (error);
@@ -4438,7 +4474,7 @@ attachment_save_dialog_response_cb (GtkWidget *fc,
                g_free (filename);
                
                if (error) {
-                       ev_window_error_dialog (GTK_WINDOW (fc),
+                       ev_window_error_dialog (GTK_WINDOW (ev_window),
                                                _("The attachment could not be saved."),
                                                error);
                        g_error_free (error);