From: Carlos Garcia Campos Date: Sat, 13 Jan 2007 13:16:13 +0000 (+0000) Subject: Do Save a copy in atomic way. Fixes bug #328266. X-Git-Tag: EVINCE_0_7_2~100 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=aaea26139003ab196a978dd7127a748d6ebca5a5;p=evince.git Do Save a copy in atomic way. Fixes bug #328266. 2007-01-13 Carlos Garcia Campos * shell/ev-window.c: (file_save_dialog_response_cb): Do Save a copy in atomic way. Fixes bug #328266. svn path=/trunk/; revision=2221 --- diff --git a/ChangeLog b/ChangeLog index c64ddd11..2f0bf612 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-01-13 Carlos Garcia Campos + + * 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 * shell/ev-sidebar-links.c: (update_page_callback_foreach): diff --git a/shell/ev-window.c b/shell/ev-window.c index ba8de920..07080e74 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -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);