diff options
author | Claudio Saavedra <csaavedra@igalia.com> | 2013-01-28 00:02:53 +0800 |
---|---|---|
committer | Claudio Saavedra <csaavedra@igalia.com> | 2013-01-28 00:02:53 +0800 |
commit | 9483e9e52af9b36ad41215063b616e960928d78a (patch) | |
tree | 7f8eb94758808f74871dd9ff9833434a1685ce49 | |
parent | 213b032a24ac9286af1f5ab3a4087d64eef12f52 (diff) | |
download | gsoc2013-epiphany-9483e9e52af9b36ad41215063b616e960928d78a.tar.gz gsoc2013-epiphany-9483e9e52af9b36ad41215063b616e960928d78a.tar.zst gsoc2013-epiphany-9483e9e52af9b36ad41215063b616e960928d78a.zip |
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().
-rw-r--r-- | doc/reference/epiphany-sections.txt | 1 | ||||
-rw-r--r-- | lib/ephy-file-helpers.c | 109 | ||||
-rw-r--r-- | lib/ephy-file-helpers.h | 2 | ||||
-rw-r--r-- | tests/ephy-file-helpers-test.c | 73 |
4 files changed, 0 insertions, 185 deletions
diff --git a/doc/reference/epiphany-sections.txt b/doc/reference/epiphany-sections.txt index 180a7501d..4260f1941 100644 --- a/doc/reference/epiphany-sections.txt +++ b/doc/reference/epiphany-sections.txt @@ -173,7 +173,6 @@ ephy_file_helpers_shutdown ephy_file_launch_application ephy_file_launch_desktop_file ephy_file_launch_handler -ephy_file_switch_temp_file ephy_file_tmp_dir ephy_file_tmp_filename ephy_file_create_data_uri_for_filename 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 @@ -551,115 +551,6 @@ ephy_file_find (const char *path, } /** - * 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, diff --git a/tests/ephy-file-helpers-test.c b/tests/ephy-file-helpers-test.c index dcb6cc539..c33c1da82 100644 --- a/tests/ephy-file-helpers-test.c +++ b/tests/ephy-file-helpers-test.c @@ -290,76 +290,6 @@ test_ephy_file_create_delete_tmp (void) ephy_file_helpers_shutdown (); } -static void -test_ephy_file_switch_temp_file (void) -{ - char *tmp_file; - - GFile *orig; - char *orig_path; - - GFile *dest; - char *dest_path; - char *file_cont = NULL; - - ephy_file_helpers_init (NULL, EPHY_FILE_HELPERS_PRIVATE_PROFILE, NULL); - - /* Empty dest */ - tmp_file = ephy_file_tmp_filename ("test-dest-XXXXXX", NULL); - dest_path = g_build_filename (ephy_file_tmp_dir (), tmp_file, NULL); - g_free (tmp_file); - - g_assert (g_file_test (dest_path, G_FILE_TEST_EXISTS) == FALSE); - dest = g_file_new_for_path (dest_path); - - tmp_file = ephy_file_tmp_filename ("test-orig-XXXXXX", NULL); - orig_path = g_build_filename (ephy_file_tmp_dir (), tmp_file, NULL); - g_free (tmp_file); - - g_assert (g_file_test (orig_path, G_FILE_TEST_EXISTS) == FALSE); - orig = g_file_new_for_path (orig_path); - - g_file_set_contents (orig_path, "orig", -1, NULL); - g_assert (g_file_test (orig_path, G_FILE_TEST_EXISTS)); - - g_test_message ("SWITCH: %s to %s", orig_path, dest_path); - - g_assert (ephy_file_switch_temp_file (dest, orig)); - g_assert (g_file_test (orig_path, G_FILE_TEST_EXISTS) == FALSE); - g_assert (g_file_test (dest_path, G_FILE_TEST_EXISTS)); - - g_assert (g_file_get_contents (dest_path, &file_cont, NULL, NULL)); - g_assert_cmpstr ("orig", ==, file_cont); - g_free (file_cont); - - ephy_file_delete_uri (g_file_get_uri (dest)); - g_assert (g_file_test (dest_path, G_FILE_TEST_EXISTS) == FALSE); - - /* Full replace */ - g_file_set_contents (dest_path, "dest", -1, NULL); - g_assert (g_file_test (dest_path, G_FILE_TEST_EXISTS)); - - g_file_set_contents (orig_path, "orig", -1, NULL); - g_assert (g_file_test (orig_path, G_FILE_TEST_EXISTS)); - - g_test_message ("SWITCH REPLACE: %s to %s", orig_path, dest_path); - g_assert (ephy_file_switch_temp_file (dest, orig)); - g_assert (g_file_test (dest_path, G_FILE_TEST_EXISTS)); - g_assert (g_file_test (orig_path, G_FILE_TEST_EXISTS) == FALSE); - - g_assert (g_file_get_contents (dest_path, &file_cont, NULL, NULL)); - g_assert_cmpstr ("orig", ==, file_cont); - g_free (file_cont); - - g_free (orig_path); - g_free (dest_path); - - g_object_unref (orig); - g_object_unref (dest); - - ephy_file_helpers_shutdown (); -} - typedef struct { const char *filename; const char *expected; @@ -425,9 +355,6 @@ main (int argc, char *argv[]) g_test_add_func ("/lib/ephy-file-helpers/create_delete_tmp", test_ephy_file_create_delete_tmp); - g_test_add_func ("/lib/ephy-file-helpers/switch_temp_file", - test_ephy_file_switch_temp_file); - g_test_add_func ("/lib/ephy-file-helpers/sanitize_filename", test_ephy_sanitize_filename); |