From 9483e9e52af9b36ad41215063b616e960928d78a Mon Sep 17 00:00:00 2001 From: Claudio Saavedra Date: Sun, 27 Jan 2013 18:02:53 +0200 Subject: ephy-file-helpers: remove ephy_file_switch_temp_file() It is racy and it is unnecessary as we've replaced all its instances with g_file_set_contents(). --- lib/ephy-file-helpers.c | 109 ------------------------------------------------ lib/ephy-file-helpers.h | 2 - 2 files changed, 111 deletions(-) (limited to 'lib') diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c index b21b8a7f5..a55d45389 100644 --- a/lib/ephy-file-helpers.c +++ b/lib/ephy-file-helpers.c @@ -550,115 +550,6 @@ ephy_file_find (const char *path, return ret; } -/** - * ephy_file_switch_temp_file: - * @file_dest: destination file - * @file_temp: file to move to @file - * - * Moves @file_temp to @file_dest atomically, doing a backup and restoring it if - * something fails. - * - * Returns: %TRUE if the switch was successful - **/ -gboolean -ephy_file_switch_temp_file (GFile *file_dest, - GFile *file_temp) -{ - char *file_dest_path, *file_temp_path; - char *backup_path; - gboolean dest_exists; - gboolean retval = TRUE; - GFile *backup_file; - GError *error = NULL; - - file_dest_path = g_file_get_path (file_dest); - file_temp_path = g_file_get_path (file_temp); - - dest_exists = g_file_test (file_dest_path, G_FILE_TEST_EXISTS); - - backup_path = g_strconcat (file_dest_path, ".old", NULL); - backup_file = g_file_new_for_path (backup_path); - - if (dest_exists) - { - if (g_file_move (file_dest, backup_file, - G_FILE_COPY_OVERWRITE, - NULL, NULL, NULL, &error) == FALSE) - { - g_warning ("Failed to backup %s to %s: %s", - file_dest_path, backup_path, - error ? error->message : "No error set"); - - if (error) - { - g_error_free (error); - error = NULL; - } - - retval = FALSE; - goto failed; - } - } - - if (g_file_move (file_temp, file_dest, - G_FILE_COPY_OVERWRITE, - NULL, NULL, NULL, &error) == FALSE) - { - g_warning ("Failed to replace %s with %s: %s", - file_temp_path, file_dest_path, - error ? error->message : "No error set"); - - if (error) - { - g_error_free (error); - error = NULL; - } - - if (g_file_move (backup_file, file_dest, - G_FILE_COPY_OVERWRITE, - NULL, NULL, NULL, &error) == FALSE) - { - g_warning ("Failed to restore %s from %s: %s", - file_dest_path, file_temp_path, - error ? error->message : "No error set"); - - if (error) - { - g_error_free (error); - error = NULL; - } - } - - retval = FALSE; - goto failed; - } - - if (dest_exists) - { - if (g_file_delete (backup_file, NULL, &error) == FALSE) - { - g_warning ("Failed to delete old file %s: %s", - backup_path, - error ? error->message : "No error set"); - - if (error) - { - g_error_free (error); - error = NULL; - } - } - } - -failed: - g_free (file_dest_path); - g_free (file_temp_path); - - g_free (backup_path); - g_object_unref (backup_file); - - return retval; -} - /** * ephy_file_delete_on_exit: * @file: a #GFile diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h index 5eed9edf7..28c83b24b 100644 --- a/lib/ephy-file-helpers.h +++ b/lib/ephy-file-helpers.h @@ -68,8 +68,6 @@ gboolean ephy_ensure_dir_exists (const char GSList * ephy_file_find (const char *path, const char *fname, gint maxdepth); -gboolean ephy_file_switch_temp_file (GFile *file_dest, - GFile *file_temp); void ephy_file_delete_on_exit (GFile *file); EphyMimePermission ephy_file_check_mime (const char *mime_type); gboolean ephy_file_launch_desktop_file (const char *filename, -- cgit v1.2.3