diff options
author | Michael Catanzaro <mcatanzaro@redhat.com> | 2022-04-29 15:21:31 -0500 |
---|---|---|
committer | Michael Catanzaro <mcatanzaro@gnome.org> | 2022-05-06 20:57:07 +0000 |
commit | e198bd85c1c7503360720e088a15341804a2628b (patch) | |
tree | 8f93d886526d6d6bec21abba4fc57d580df599a8 /tests | |
parent | 02aa85900da2765c4b4935e3cc91d2c776f7171e (diff) | |
download | epiphany-e198bd85c1c7503360720e088a15341804a2628b.tar.gz |
file-helpers: always delete tmp directory
The KEEP_DIRECTORY flag is being misinterpreted as indication that
the profile directory should not be deleted. In fact, it controls
whether the Epiphany temporary directory is deleted. And that should
always be deleted, because leaving temp directories around is
unfriendly, so get rid of it altogether.
Fixes #1768
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1108>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ephy-file-helpers-test.c | 76 |
1 files changed, 17 insertions, 59 deletions
diff --git a/tests/ephy-file-helpers-test.c b/tests/ephy-file-helpers-test.c index a591e2b58..817e3c1c9 100644 --- a/tests/ephy-file-helpers-test.c +++ b/tests/ephy-file-helpers-test.c @@ -27,75 +27,33 @@ #include <glib.h> #include <gtk/gtk.h> -typedef struct { - const char *dir; - EphyFileHelpersFlags flags; -} FileInitTest; - -static const FileInitTest private_tests[] = { - { "private", EPHY_FILE_HELPERS_PRIVATE_PROFILE }, - { "private, keep-dir", EPHY_FILE_HELPERS_PRIVATE_PROFILE | EPHY_FILE_HELPERS_KEEP_DIR } -}; - static void test_ephy_file_helpers_init (void) { - guint i; - - for (i = 0; i < G_N_ELEMENTS (private_tests); i++) { - FileInitTest test; - - char *tmp_dir = NULL; - char *profile_dir = NULL; + char *tmp_dir = NULL; + char *profile_dir = NULL; - gboolean private_profile = FALSE; - gboolean keep_dir = FALSE; - gboolean ensure_exists = FALSE; + g_assert_null (ephy_profile_dir ()); + g_assert_true (ephy_file_helpers_init (NULL, EPHY_FILE_HELPERS_PRIVATE_PROFILE, NULL)); - test = private_tests[i]; + tmp_dir = g_strdup (ephy_file_tmp_dir ()); + profile_dir = g_strdup (ephy_profile_dir ()); - if (test.flags & EPHY_FILE_HELPERS_PRIVATE_PROFILE) private_profile = TRUE; - if (test.flags & EPHY_FILE_HELPERS_KEEP_DIR) keep_dir = TRUE; - if (test.flags & EPHY_FILE_HELPERS_ENSURE_EXISTS) ensure_exists = TRUE; + g_assert_nonnull (tmp_dir); + g_assert_nonnull (profile_dir); - g_test_message ("INIT: dir: %s; private: %s; keep_dir: %s; ensure_exists: %s", - test.dir, - private_profile ? "TRUE" : "FALSE", - keep_dir ? "TRUE" : "FALSE", - ensure_exists ? "TRUE" : "FALSE"); + /* Should always exist after ephy_file_tmp_dir(). */ + g_assert_true (g_file_test (tmp_dir, G_FILE_TEST_EXISTS)); + g_assert_false (g_file_test (profile_dir, G_FILE_TEST_EXISTS)); - g_assert_null (ephy_profile_dir ()); - g_assert_true (ephy_file_helpers_init (NULL, test.flags, NULL)); - - tmp_dir = g_strdup (ephy_file_tmp_dir ()); - profile_dir = g_strdup (ephy_profile_dir ()); - - g_assert_nonnull (tmp_dir); - g_assert_nonnull (profile_dir); - - /* Should always exist after ephy_file_tmp_dir(). */ - g_assert_true (g_file_test (tmp_dir, G_FILE_TEST_EXISTS)); - g_assert_true (g_file_test (profile_dir, G_FILE_TEST_EXISTS) == ensure_exists); - - ephy_file_helpers_shutdown (); - - /* Private profiles have their profile_dir inside tmp_dir. */ - g_assert_true (g_file_test (tmp_dir, G_FILE_TEST_EXISTS) == keep_dir); - g_assert_true (g_file_test (profile_dir, G_FILE_TEST_EXISTS) == (keep_dir && ensure_exists)); + ephy_file_helpers_shutdown (); - /* Cleanup dir left behind. */ - if (keep_dir) { - /* As a safety measure, only try recursive delete on paths - * prefixed with /tmp. */ - if (g_str_has_prefix (tmp_dir, "/tmp")) - g_assert_true (ephy_file_delete_dir_recursively (tmp_dir, NULL)); - else - g_warning ("INIT: dangerous path returned as tmp_dir: %s", tmp_dir); - } + /* Private profiles have their profile_dir inside tmp_dir. */ + g_assert_false (g_file_test (tmp_dir, G_FILE_TEST_EXISTS)); + g_assert_false (g_file_test (profile_dir, G_FILE_TEST_EXISTS)); - g_free (tmp_dir); - g_free (profile_dir); - } + g_free (tmp_dir); + g_free (profile_dir); } typedef struct { |