From 8205e18cb651de99de58b7ea5779bc3fbaea69b5 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Thu, 22 Jan 2004 19:23:06 +0000 Subject: New function to get temp directory and moved ephy_shell_delete_on_exit to 2004-01-22 Christopher James Lahey * lib/ephy-file-helpers.c, lib/ephy-file-helpers.h (ephy_file_tmp_directory, ephy_file_delete_on_exit): New function to get temp directory and moved ephy_shell_delete_on_exit to here. * lib/widgets/ephy-location-entry.c: Changed how this goes about showing itself when hidden and activated. * src/ephy-shell.c, src/ephy-shell.h (ephy_shell_delete_on_exit): Moved to ephy_file_delete_on_exit. * src/window-commands.c: Changed ephy_shell_delete_on_exit to ephy_file_delete_on_exit. Used ephy_file_tmp_directory to save source files for viewing in a directory that isn't world readable. --- lib/ephy-file-helpers.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'lib/ephy-file-helpers.c') diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c index 1161f6ac7..db988a2e3 100644 --- a/lib/ephy-file-helpers.c +++ b/lib/ephy-file-helpers.c @@ -35,6 +35,29 @@ static GHashTable *files = NULL; static char *dot_dir = NULL; +static char *tmp_dir = NULL; +static GList *del_on_exit = NULL; + +char * +ephy_file_tmp_directory (void) +{ + if (tmp_dir == NULL) + { + char *partial_name; + char *full_name; + + partial_name = g_strconcat ("epiphany-", g_get_user_name (), "-XXXXXX", NULL); + full_name = g_build_filename (g_get_tmp_dir (), partial_name, NULL); + tmp_dir = mkdtemp (full_name); + g_free(partial_name); + if (tmp_dir == NULL) + { + g_free (full_name); + } + } + + return tmp_dir; +} char * ephy_file_tmp_filename (const char *base, @@ -128,12 +151,32 @@ ephy_file_helpers_init (void) (GDestroyNotify) g_free); } +static void +delete_files (GList *l) +{ + for (; l != NULL; l = l->next) + { + unlink (l->data); + } +} + void ephy_file_helpers_shutdown (void) { g_hash_table_destroy (files); + del_on_exit = g_list_reverse (del_on_exit); + delete_files (del_on_exit); + g_list_foreach (del_on_exit, (GFunc)g_free, NULL); + g_list_free (del_on_exit); + del_on_exit = NULL; + + rmdir (tmp_dir); + g_free (tmp_dir); + tmp_dir = NULL; + g_free (dot_dir); + dot_dir = NULL; } void @@ -237,3 +280,10 @@ failed: return retval; } + +void +ephy_file_delete_on_exit (const char *path) +{ + del_on_exit = g_list_prepend (del_on_exit, + g_strdup (path)); +} -- cgit v1.2.3