[epiphany] Based on a patch by Jon McCann.



commit 850104ef1d0b44a92fcda554d0691ed40a902c15
Author: Xan Lopez <xan igalia com>
Date:   Wed Apr 25 23:33:53 2012 -0400

    Based on a patch by Jon McCann.
    
    Migrate profile directory to XDG config dir
    
    https://bugzilla.gnome.org/show_bug.cgi?id=522810

 lib/ephy-file-helpers.c     |    5 +--
 lib/ephy-file-helpers.h     |    3 --
 lib/ephy-profile-migrator.c |   63 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 6 deletions(-)
---
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 63f3c14..414dd9e 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 68a6db6..bdabf87 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 17b2692..093418c 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;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]