bug-buddy r2731 - in trunk: . src



Author: cosimoc
Date: Fri Sep 26 19:19:38 2008
New Revision: 2731
URL: http://svn.gnome.org/viewvc/bug-buddy?rev=2731&view=rev

Log:
2008-09-26  Cosimo Cecchi  <cosimoc gnome org>

	* src/bug-buddy.c: (fill_include_file), (main):
	* src/bug-buddy.h:
	Add an option to own the included file (i.e. delete it after
	including). That only works together with the --include option
	and is disabled by default (#540150).


Modified:
   trunk/ChangeLog
   trunk/src/bug-buddy.c
   trunk/src/bug-buddy.h

Modified: trunk/src/bug-buddy.c
==============================================================================
--- trunk/src/bug-buddy.c	(original)
+++ trunk/src/bug-buddy.c	Fri Sep 26 19:19:38 2008
@@ -77,6 +77,7 @@
 	{ "appname",    '\0', 0, G_OPTION_ARG_FILENAME, &gopt_data.app_file,      N_("File name of crashed program"),            N_("FILE") },
 	{ "pid",        '\0', 0, G_OPTION_ARG_INT,      &gopt_data.pid,           N_("PID of crashed program"),                  N_("PID") },
 	{ "include",    '\0', 0, G_OPTION_ARG_FILENAME, &gopt_data.include_file,  N_("Text file to include in the report"),      N_("FILE") },
+	{ "own-file",   '\0', 0, G_OPTION_ARG_NONE, &gopt_data.own_file,          N_("Delete the included file after reporting"),NULL},
 	{ "minidump",   '\0', 0, G_OPTION_ARG_FILENAME, &gopt_data.minidump_file, N_("MiniDump file with info about the crash"), N_("FILE") },
 	{ NULL }
 };
@@ -1600,20 +1601,33 @@
 }
 
 static void
-fill_include_file (char *filename, GtkBuilder *ui)
+fill_include_file (char *filename, gboolean own_file, GtkBuilder *ui)
 {
 	GtkTextView *text_view;
 	GtkTextIter end;
 	GtkTextBuffer *buffer;
 	char *text;
+	gboolean res;
 	GError *error = NULL;
 
-	if (g_file_get_contents (filename, &text, NULL, &error) != TRUE) {
+	res = g_file_get_contents (filename, &text, NULL, &error);
+
+	/* if own_file is set, delete the file regardless of the result:
+	 * if _get_contents () fails chances are the file has already been
+	 * deleted anyway.
+ 	 */
+
+	if (own_file) {
+		if (g_unlink (filename) == -1)
+			g_warning ("Unable to delete %s", filename);
+	}
+
+	if (!res) {
 		buddy_error (NULL, error->message);
 		g_error_free (error);
 		return;
 	}
-	
+
 	text_view = GTK_TEXT_VIEW (gtk_builder_get_object (ui, "gdb-text"));
 	buffer = gtk_text_view_get_buffer (text_view);
 	gtk_text_buffer_get_end_iter (buffer, &end);
@@ -1623,7 +1637,6 @@
 
 }
 
-
 static void
 fill_system_info (GtkBuilder *ui)
 {
@@ -1837,7 +1850,12 @@
             gopt_data.minidump_file == NULL) {
 		buddy_error (NULL, _("Either --pid , --include or --minidump arguments are required.\n"));	
 		return 0;
-	}	
+	}
+
+	if (gopt_data.own_file == TRUE && gopt_data.include_file == NULL) {
+		buddy_error (NULL, _("The --own-file option needs a --include argument.\n"));
+		return 0;
+	}
 	
 	/* get some information about the gnome version */
 	gnome_version = get_gnome_version_info ();
@@ -1981,7 +1999,7 @@
 	}
 	
 	if (gopt_data.include_file != NULL) {
-		fill_include_file (gopt_data.include_file, ui);
+		fill_include_file (gopt_data.include_file, gopt_data.own_file, ui);
 	}
 
 	

Modified: trunk/src/bug-buddy.h
==============================================================================
--- trunk/src/bug-buddy.h	(original)
+++ trunk/src/bug-buddy.h	Fri Sep 26 19:19:38 2008
@@ -46,6 +46,9 @@
 	/* file to include */
 	gchar *include_file;
 
+	/* whether to own the included file */
+	gboolean own_file;
+
 	/* MiniDump file */
 	gchar *minidump_file;
 



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