aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXan Lopez <xan@igalia.com>2012-04-26 11:33:53 +0800
committerXan Lopez <xan@igalia.com>2012-05-08 02:29:47 +0800
commit850104ef1d0b44a92fcda554d0691ed40a902c15 (patch)
tree2cf91859f803225814add15b0715942dd82e6ca8
parent3847db0803addac9f0b90dc86767d8f65768d4ad (diff)
downloadgsoc2013-epiphany-850104ef1d0b44a92fcda554d0691ed40a902c15.tar
gsoc2013-epiphany-850104ef1d0b44a92fcda554d0691ed40a902c15.tar.gz
gsoc2013-epiphany-850104ef1d0b44a92fcda554d0691ed40a902c15.tar.bz2
gsoc2013-epiphany-850104ef1d0b44a92fcda554d0691ed40a902c15.tar.lz
gsoc2013-epiphany-850104ef1d0b44a92fcda554d0691ed40a902c15.tar.xz
gsoc2013-epiphany-850104ef1d0b44a92fcda554d0691ed40a902c15.tar.zst
gsoc2013-epiphany-850104ef1d0b44a92fcda554d0691ed40a902c15.zip
Based on a patch by Jon McCann.
Migrate profile directory to XDG config dir https://bugzilla.gnome.org/show_bug.cgi?id=522810
-rw-r--r--lib/ephy-file-helpers.c5
-rw-r--r--lib/ephy-file-helpers.h3
-rw-r--r--lib/ephy-profile-migrator.c63
3 files changed, 65 insertions, 6 deletions
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 63f3c1434..414dd9e60 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -278,7 +278,7 @@ ephy_dot_dir (void)
* Initializes Epiphany file helper functions, sets @profile_dir as Epiphany's
* profile dir and whether the running session will be private.
*
- * Returns: %FALSE if the profile dir couldn't be created or accesed
+ * Returns: %FALSE if the profile dir couldn't be created or accessed
**/
gboolean
ephy_file_helpers_init (const char *profile_dir,
@@ -331,8 +331,7 @@ ephy_file_helpers_init (const char *profile_dir,
}
else
{
- dot_dir = g_build_filename (g_get_home_dir (),
- GNOME_DOT_GNOME,
+ dot_dir = g_build_filename (g_get_user_config_dir (),
"epiphany",
NULL);
}
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index 68a6db616..bdabf87c1 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -30,9 +30,6 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
-/* From libgnome */
-#define GNOME_DOT_GNOME ".gnome2"
-
extern GQuark ephy_file_helpers_error_quark;
#define EPHY_FILE_HELPERS_ERROR_QUARK (ephy_file_helpers_error_quark)
diff --git a/lib/ephy-profile-migrator.c b/lib/ephy-profile-migrator.c
index 17b2692ac..093418c30 100644
--- a/lib/ephy-profile-migrator.c
+++ b/lib/ephy-profile-migrator.c
@@ -41,10 +41,13 @@
#include "ephy-nss-glue.h"
#endif
+#include <fcntl.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <gnome-keyring.h>
#include <libsoup/soup-gnome.h>
+#include <sys/stat.h>
+#include <sys/types.h>
/*
* What to do to add new migration steps:
@@ -620,6 +623,62 @@ migrate_tabs_visibility ()
EPHY_PREFS_UI_TABS_BAR_VISIBILITY_POLICY_ALWAYS);
}
+static void
+migrate_profile (const char *old_dir,
+ const char *new_dir)
+{
+ char *parent_dir;
+ char *updated;
+ const char *message;
+
+ if (g_file_test (new_dir, G_FILE_TEST_EXISTS) ||
+ !g_file_test (old_dir, G_FILE_TEST_IS_DIR))
+ return;
+
+ /* Test if we already attempted to migrate first. */
+ updated = g_build_filename (old_dir, "DEPRECATED-DIRECTORY", NULL);
+ message = _("Epiphany 3.6 deprecated this directory and tried migrating "
+ "this configuration to ~/.config/epiphany");
+
+ parent_dir = g_path_get_dirname (new_dir);
+ if (g_mkdir_with_parents (parent_dir, 0700) == 0) {
+ int fd, res;
+
+ /* rename() works fine if the destination directory is empty. */
+ res = g_rename (old_dir, new_dir);
+ if (res == -1 && !g_file_test (updated, G_FILE_TEST_EXISTS)) {
+ fd = g_creat (updated, 0600);
+ if (fd != -1) {
+ res = write (fd, message, strlen (message));
+ close (fd);
+ }
+ }
+ }
+
+ g_free (parent_dir);
+ g_free (updated);
+}
+
+static void
+migrate_profile_gnome2_to_xdg ()
+{
+ char *old_dir;
+ char *new_dir;
+
+ old_dir = g_build_filename (g_get_home_dir (),
+ ".gnome2",
+ "epiphany",
+ NULL);
+ new_dir = g_build_filename (g_get_user_config_dir (),
+ "epiphany",
+ NULL);
+
+ migrate_profile (old_dir, new_dir);
+
+ g_free (new_dir);
+ g_free (old_dir);
+}
+
const EphyProfileMigrator migrators[] = {
migrate_cookies,
migrate_passwords,
@@ -643,6 +702,10 @@ ephy_migrator ()
LOG ("Running migrators up to version %d, current migration version is %d.",
EPHY_PROFILE_MIGRATION_VERSION, latest);
+ /* Always try to migrate the data from the old profile dir at the
+ * very beginning. */
+ migrate_profile_gnome2_to_xdg ();
+
for (i = latest; i < EPHY_PROFILE_MIGRATION_VERSION; i++) {
EphyProfileMigrator m;