[Gnome-print] temp files



As of version 0.29, gnome-print doesn't clean up the temporary files
(postscript headers) it writes.  In fact it can't, because there is no
mechanism for remembering what the files are called.  The attached
little patch against gnome-print-ps2.c fixes that.

Sorry if this has been worked over already.  I have too many irons in
the fire to research gnome-print CVS.

Allin Cottrell
Wake Forest University
--- gnome-print-ps2.c.orig	Wed Oct  3 08:53:08 2001
+++ gnome-print-ps2.c	Wed Oct  3 18:06:29 2001
@@ -102,6 +102,8 @@
 	gint ps_level;
 
 	FILE *buf;
+    
+	gchar *tmpfile;
 
 	ArtDRect bbox;
 };
@@ -211,6 +213,7 @@
 	ps2->pages = NULL;
 
 	ps2->buf = NULL;
+	ps2->tmpfile = NULL;
 
 	/* We empty bbox here, as the real thing has to be filled in ::new */
 	ps2->bbox.x0 = ps2->bbox.y0 = 0.0;
@@ -652,6 +655,10 @@
 	}
 	fclose (ps2->buf);
 	ps2->buf = NULL;
+	if (ps2->tmpfile) {
+	        remove (ps2->tmpfile);
+	        g_free (ps2->tmpfile);
+	}
 
 	gnome_print_context_fprintf (pc, "%%%%Trailer" EOL);
 	gnome_print_context_fprintf (pc, "%%%%EOF" EOL);
@@ -893,7 +900,6 @@
 	GnomePrintPs2 *ps2;
 	const GnomePaper *paper;
 	gint fd;
-	gchar *c;
 
 	g_return_val_if_fail (printer != NULL, NULL);
 	g_return_val_if_fail (GNOME_IS_PRINTER (printer), NULL);
@@ -921,11 +927,12 @@
 	
 #endif
 
-	c = g_strdup ("/tmp/gnome-print-XXXXXX");
-	fd = mkstemp (c);
-	g_free (c);
+	ps2->tmpfile = g_strdup ("/tmp/gnome-print-XXXXXX");
+	fd = mkstemp (ps2->tmpfile);
 	if (fd < 0) {
 		g_warning ("Cannot create temporary file");
+		g_free (ps2->tmpfile);
+		ps2->tmpfile = NULL;
 		gtk_object_unref (GTK_OBJECT (ps2));
 		return NULL;
 	}


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