[gitg] Make format patch override existing files properly (fixes #620463)



commit 9c311b59c9c006d22bbf0223478e57e524cfb011
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sat Oct 23 14:49:05 2010 +0200

    Make format patch override existing files properly (fixes #620463)

 gitg/gitg-branch-actions.c |   16 +++++++++-------
 gitg/gitg-window.c         |   29 +++++++++++++++++++++++++----
 2 files changed, 34 insertions(+), 11 deletions(-)
---
diff --git a/gitg/gitg-branch-actions.c b/gitg/gitg-branch-actions.c
index 43320a7..17ef96e 100644
--- a/gitg/gitg-branch-actions.c
+++ b/gitg/gitg-branch-actions.c
@@ -1921,9 +1921,9 @@ on_format_patch_update (GitgRunner       *runner,
 }
 
 GitgRunner *
-gitg_branch_actions_format_patch (GitgWindow     *window,
-                                  GitgRevision   *revision,
-                                  gchar const    *destination)
+gitg_branch_actions_format_patch (GitgWindow   *window,
+                                  GitgRevision *revision,
+                                  gchar const  *destination)
 {
 	g_return_val_if_fail (GITG_IS_WINDOW (window), NULL);
 	g_return_val_if_fail (revision != NULL, NULL);
@@ -1932,10 +1932,12 @@ gitg_branch_actions_format_patch (GitgWindow     *window,
 	GitgRunner *ret;
 
 	GFile *file = g_file_new_for_uri (destination);
-	GFileOutputStream *stream = g_file_create (file,
-	                                           G_FILE_CREATE_REPLACE_DESTINATION,
-	                                           NULL,
-	                                           NULL);
+	GFileOutputStream *stream = g_file_replace (file,
+	                                            NULL,
+	                                            FALSE,
+	                                            G_FILE_CREATE_REPLACE_DESTINATION,
+	                                            NULL,
+	                                            NULL);
 	g_object_unref (file);
 
 	if (!stream)
diff --git a/gitg/gitg-window.c b/gitg/gitg-window.c
index f0f6315..2699216 100644
--- a/gitg/gitg-window.c
+++ b/gitg/gitg-window.c
@@ -3345,11 +3345,29 @@ on_format_patch_response (GtkDialog       *dialog,
 		if (!info->revisions->next)
 		{
 			gchar *uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
-			gitg_window_add_branch_action (info->window,
-			                               gitg_branch_actions_format_patch (info->window,
-			                                                                 info->revisions->data,
-			                                                                 uri));
+			gboolean ret;
+
+			ret = gitg_window_add_branch_action (info->window,
+			                                     gitg_branch_actions_format_patch (info->window,
+			                                                                       info->revisions->data,
+			                                                                       uri));
 			g_free (uri);
+
+			if (!ret)
+			{
+				GtkWidget *dlg = gtk_message_dialog_new (GTK_WINDOW (dialog),
+				                                         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+				                                         GTK_MESSAGE_ERROR,
+				                                         GTK_BUTTONS_OK,
+				                                         _ ("Format patch failed for unknown reason"));
+
+				gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
+				                                          "%s",
+				                                          _("Please check if you have the right permissions to write the file"));
+
+				g_signal_connect (dlg, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+				gtk_widget_show (dlg);
+			}
 		}
 		else
 		{
@@ -3393,6 +3411,9 @@ on_revision_format_patch_activate (GtkAction  *action,
 		                                      GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
 		                                      NULL);
 
+		gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
+		                                                TRUE);
+
 		gchar *name = gitg_revision_get_format_patch_name (revision);
 		gchar *filename = g_strdup_printf ("0001-%s.patch", name);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]