? m4/intltool.m4
Index: libgthumb/file-utils.c
===================================================================
RCS file: /cvs/gnome/gthumb/libgthumb/file-utils.c,v
retrieving revision 1.64
diff -B -d -u -r1.64 file-utils.c
--- libgthumb/file-utils.c	31 Aug 2006 18:55:44 -0000	1.64
+++ libgthumb/file-utils.c	5 Nov 2006 19:43:34 -0000
@@ -1882,42 +1882,48 @@
 
 /* temp */
 
-
+/* NOTE: the directory created by this function must deleted when no longer 
+needed. (delete all temporary files and use dir_remove() */
+/* NOTE: the pointer returned by this function must be freed using g_free() */
 char *
 get_temp_dir_name (void)
 {
-	static int  count = 0;
-	char       *tmp_dir = NULL;
+	char       *tmppath;
+	char       *retval;
 	
-	do {
-		g_free (tmp_dir);
-		tmp_dir = g_strdup_printf ("%s%s.%d.%d",
-					   g_get_tmp_dir (),
-					   "/gthumb",
-					   getpid (),
-					   count++);
-
-	} while (path_is_dir (tmp_dir));
-
-	if (! dir_make (tmp_dir, 0700)) {
-		g_free (tmp_dir);
-		tmp_dir = NULL;
-	}
+	tmppath = (char*) g_build_filename (g_get_tmp_dir (), "gthumb.XXXXXX", NULL);
+	
+	retval = mkdtemp(tmppath);
+	if (retval == NULL)
+		g_free(tmppath);
 
-	return tmp_dir;
+	return retval;
 }
 
 
+/* WARNING: this is not secure unless only the current user has write access to 
+tmpdir.  Use get_temp_dir_name to create tmpdir securely. */
+/* NOTE: the pointer returned by this function must be freed using g_free() */
 char *
-get_temp_file_name (const char *ext)
+get_temp_file_name (const char* tmpdir, const char *ext)
 {
-	char *dir, *name, *filename;
+	char *name, *filename;
+	static GStaticMutex count_mutex = G_STATIC_MUTEX_INIT;
+	static int count = 0;
+	
+	if (tmpdir == NULL)
+		return NULL;
+
+	g_static_mutex_lock(&count_mutex);
+	if (ext != NULL)
+		name = g_strdup_printf("%d%s", count++, ext);
+	else
+		name = g_strdup_printf("%d", count++);
+	g_static_mutex_unlock(&count_mutex);
+	
+	filename = g_build_filename (tmpdir, name, NULL);
 
-	dir = get_temp_dir_name ();
-	name = g_strconcat ("temp", ext, NULL);
-	filename = g_build_filename (dir, name, NULL);
 	g_free (name);
-	g_free (dir);
 	
 	return filename;
 }
Index: libgthumb/file-utils.h
===================================================================
RCS file: /cvs/gnome/gthumb/libgthumb/file-utils.h,v
retrieving revision 1.30
diff -B -d -u -r1.30 file-utils.h
--- libgthumb/file-utils.h	16 Mar 2006 19:12:25 -0000	1.30
+++ libgthumb/file-utils.h	5 Nov 2006 19:43:35 -0000
@@ -183,7 +183,8 @@
 /* temp */
 
 char *              get_temp_dir_name             (void);
-char *              get_temp_file_name            (const char       *ext);
+char *              get_temp_file_name            (const char       *tmpdir,
+						   const char       *ext);
 
 /* VFS extensions */
 
Index: src/dlg-photo-importer.c
===================================================================
RCS file: /cvs/gnome/gthumb/src/dlg-photo-importer.c,v
retrieving revision 1.45
diff -B -d -u -r1.45 dlg-photo-importer.c
--- src/dlg-photo-importer.c	5 Nov 2006 13:22:37 -0000	1.45
+++ src/dlg-photo-importer.c	5 Nov 2006 19:43:37 -0000
@@ -405,26 +405,6 @@
 }
 
 
-static char*
-get_temp_filename (void)
-{
-	char       *result = NULL;
-        static int  count = 0;
-        int         try = 0;
- 
-	do {
-		g_free (result);
-		result = g_strdup_printf ("%s%s.%d.%d",
-					  g_get_tmp_dir (),
-					  "/gthumb",
-					  getpid (),
-					  count++);
-	} while (path_is_file (result) && (try++ < MAX_TRIES));
- 
-        return result;
-}
-
-
 static void
 display_error_dialog (DialogData *data,
 		      const char *msg1,
@@ -741,8 +721,17 @@
 	CameraFile *file;
 	char       *camera_folder;
 	const char *camera_filename;
+	char       *tmp_dir;
 	char       *tmp_filename;
 
+	tmp_dir = get_temp_dir_name ();
+	if (tmp_dir == NULL)
+	{
+		/* should we display an error message here? */
+		return;
+	}
+	tmp_filename = get_temp_file_name (tmp_dir, NULL);
+
 	gp_file_new (&file);
 
 	camera_folder = remove_level_from_path (camera_path);
@@ -754,8 +743,6 @@
 			    file, 
 			    data->context);
 	
-	tmp_filename = get_temp_filename ();
-
 	if (gp_file_save (file, tmp_filename) >= 0) {
 		GdkPixbuf *pixbuf;
 		int        width, height;
@@ -791,6 +778,8 @@
 	}
 
 	g_free (tmp_filename);
+	dir_remove (tmp_dir);
+	g_free (tmp_dir);
 	g_free (camera_folder);
 	
 	gp_file_unref (file);
Index: src/gth-window-actions-callbacks.c
===================================================================
RCS file: /cvs/gnome/gthumb/src/gth-window-actions-callbacks.c,v
retrieving revision 1.23
diff -B -d -u -r1.23 gth-window-actions-callbacks.c
--- src/gth-window-actions-callbacks.c	5 Nov 2006 13:22:42 -0000	1.23
+++ src/gth-window-actions-callbacks.c	5 Nov 2006 19:43:39 -0000
@@ -24,6 +24,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <unistd.h>
 
 #include <gconf/gconf-client.h>
 #include <libgnome/gnome-exec.h>
@@ -192,6 +193,7 @@
 				       GthWindow *window)
 {
 	GList    *list;
+	char     *tmp_dir;
 	char     *tmp_filename = NULL;
 	gboolean  remove_temp_file = FALSE;
 
@@ -211,7 +213,13 @@
 			GList      *current;
 
 			g_object_ref (pixbuf);
-			tmp_filename = get_temp_file_name (".jpeg");
+			tmp_dir = get_temp_dir_name ();
+			if (tmp_dir == NULL)
+			{
+				_gtk_error_dialog_run (GTK_WINDOW (window), _("Could not create a temporary folder"));
+				return;
+			}
+			tmp_filename = get_temp_file_name (tmp_dir, ".jpeg");
 			if (! _gdk_pixbuf_save (pixbuf,
 						tmp_filename,
 						"jpeg",
@@ -220,6 +228,8 @@
 				_gtk_error_dialog_from_gerror_run (GTK_WINDOW (window), &error);
 				g_object_unref (pixbuf);
 				g_free (tmp_filename);
+				dir_remove(tmp_dir);
+				g_free(tmp_dir);
 				return;
 			}
 
@@ -240,7 +250,11 @@
 	}
 
 	if (remove_temp_file)
+	{
 		print_catalog_dlg_full (GTK_WINDOW (window), list, print_done_cb, tmp_filename);
+		dir_remove (tmp_dir);
+		g_free (tmp_dir);
+	}
 	else
 		print_catalog_dlg (GTK_WINDOW (window), list);
 
Index: src/rotation-utils.c
===================================================================
RCS file: /cvs/gnome/gthumb/src/rotation-utils.c,v
retrieving revision 1.11
diff -B -d -u -r1.11 rotation-utils.c
--- src/rotation-utils.c	2 Nov 2006 20:26:13 -0000	1.11
+++ src/rotation-utils.c	5 Nov 2006 19:43:42 -0000
@@ -138,7 +138,7 @@
 {
 	char        *line;
 	char        *tmp;
-	static int   count = 0;
+	char        *tmpdir;
 	GError      *err = NULL;
 	JXFORM_CODE  transf;
 	char        *e1, *e2;
@@ -147,10 +147,15 @@
 	if (path == NULL)
 		return;
 	
-	tmp = g_strdup_printf ("%s/gthumb.%d.%d",
-				g_get_tmp_dir (), 
-				getpid (),
-				count++);
+	tmpdir = get_temp_dir_name ();
+	if (tmpdir == NULL)
+	{
+		_gtk_error_dialog_run (GTK_WINDOW (win), 
+				      _("Could not create a temporary folder"));
+		return;
+	}
+	
+	tmp = get_temp_file_name (tmpdir, NULL);
 
 	switch (transform) {
 	case GTH_TRANSFORM_NONE:
@@ -186,6 +191,8 @@
 		g_free (tmp);
 		if (err != NULL) 
 			_gtk_error_dialog_from_gerror_run (win, &err);
+		dir_remove (tmpdir);
+		g_free (tmpdir);
 		return;
 	}
 
@@ -194,6 +201,8 @@
 
 	line = g_strdup_printf ("mv -f %s %s", e1, e2);
 	g_spawn_command_line_sync (line, NULL, NULL, NULL, &err);  
+	dir_remove (tmpdir);
+	g_free (tmpdir);
 
 	if (err != NULL) {
 		_gtk_error_dialog_from_gerror_run (win, &err);
