[epiphany/gnome-3-18] Do not run new migrator if the main profile has been migrated



commit 6225374a94c4e6343fc32cb2426f7b5c076164c3
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Feb 2 21:31:46 2017 -0600

    Do not run new migrator if the main profile has been migrated
    
    This is ephy *profile* migrator. It runs on a per-profile basis. i.e.
    each web app runs migrators separately. So this migration step could run
    once for a profile dir, then again far in the future when an old web app
    is opened. But passwords are global state, not stored in the profile dir,
    and we want to run this migration only once. This is tricky to fix, but
    it's easier if we relax the constraint to "never run this migrator if it
    has been run already for the default profile dir." That's because we don't
    really care if a couple web app passwords get converted from insecure to
    secure, which is not a big problem and indicates the user probably never
    uses Epiphany except for web apps anyway. We just don't want all the user's
    passwords to get converted mysteriously because he happens to open a web
    app. So check the migration version for the default profile dir and abort
    if this migrator has already run there. This way we avoid adding a new flag
    file to clutter the profile dir just to check if this migrator has run.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=752738

 lib/ephy-profile-migrator.c |   22 ++++++++++++++++++++++
 lib/ephy-profile-utils.c    |   15 ++++++++++++---
 lib/ephy-profile-utils.h    |    2 ++
 3 files changed, 36 insertions(+), 3 deletions(-)
---
diff --git a/lib/ephy-profile-migrator.c b/lib/ephy-profile-migrator.c
index f3cb49e..fce3ad3 100644
--- a/lib/ephy-profile-migrator.c
+++ b/lib/ephy-profile-migrator.c
@@ -1031,8 +1031,30 @@ migrate_insecure_passwords (void)
   SecretService *service;
   GHashTable *attributes;
   GList *items;
+  int default_profile_migration_version;
   GError *error = NULL;
 
+  /* This is ephy *profile* migrator. It runs on a per-profile basis. i.e.
+   * each web app runs migrators separately. So this migration step could run
+   * once for a profile dir, then again far in the future when an old web app
+   * is opened. But passwords are global state, not stored in the profile dir,
+   * and we want to run this migration only once. This is tricky to fix, but
+   * it's easier if we relax the constraint to "never run this migrator if it
+   * has been run already for the default profile dir." That's because we don't
+   * really care if a couple web app passwords get converted from insecure to
+   * secure, which is not a big problem and indicates the user probably never
+   * uses Epiphany except for web apps anyway. We just don't want all the user's
+   * passwords to get converted mysteriously because he happens to open a web
+   * app. So check the migration version for the default profile dir and abort
+   * if this migrator has already run there. This way we avoid adding a new flag
+   * file to clutter the profile dir just to check if this migrator has run.
+   */
+  default_profile_migration_version = ephy_profile_utils_get_migration_version_for_profile_dir 
(ephy_default_dot_dir ());
+  if (default_profile_migration_version >= EPHY_INSECURE_PASSWORDS_MIGRATION_VERSION) {
+    LOG ("Skipping insecure password migration because default profile has already migrated");
+    return;
+  }
+
   service = secret_service_get_sync (SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &error);
   if (error != NULL) {
     g_warning ("Failed to get secret service proxy, insecure passwords will not be migrated: %s", 
error->message);
diff --git a/lib/ephy-profile-utils.c b/lib/ephy-profile-utils.c
index 0430582..afe3fc8 100644
--- a/lib/ephy-profile-utils.c
+++ b/lib/ephy-profile-utils.c
@@ -25,17 +25,19 @@
 #include "ephy-debug.h"
 #include "ephy-file-helpers.h"
 
+#include <string.h>
+
 #define PROFILE_MIGRATION_FILE ".migrated"
 
 int
-ephy_profile_utils_get_migration_version ()
+ephy_profile_utils_get_migration_version_for_profile_dir (const char *profile_directory)
 {
   char *migrated_file, *contents = NULL;
   gsize size;
   int result = 0;
   int latest = 0;
 
-  migrated_file = g_build_filename (ephy_dot_dir (),
+  migrated_file = g_build_filename (profile_directory,
                                     PROFILE_MIGRATION_FILE,
                                     NULL);
 
@@ -49,7 +51,8 @@ ephy_profile_utils_get_migration_version ()
 
     if (result != 1)
       latest = 0;
-  } else if (ephy_dot_dir_is_default () == FALSE) {
+  } else if (strcmp (ephy_dot_dir (), profile_directory) == 0 &&
+             ephy_dot_dir_is_default () == FALSE) {
     /* Since version 8, we need to migrate also profile directories
        other than the default one. Profiles in such directories work
        perfectly fine without going through the first 7 migration
@@ -64,6 +67,12 @@ ephy_profile_utils_get_migration_version ()
   return latest;
 }
 
+int
+ephy_profile_utils_get_migration_version (void)
+{
+  return ephy_profile_utils_get_migration_version_for_profile_dir (ephy_dot_dir ());
+}
+
 gboolean
 ephy_profile_utils_set_migration_version (int version)
 {
diff --git a/lib/ephy-profile-utils.h b/lib/ephy-profile-utils.h
index 56eb897..7da1c5a 100644
--- a/lib/ephy-profile-utils.h
+++ b/lib/ephy-profile-utils.h
@@ -23,12 +23,14 @@
 #include <glib.h>
 
 #define EPHY_PROFILE_MIGRATION_VERSION 11
+#define EPHY_INSECURE_PASSWORDS_MIGRATION_VERSION 11
 
 #define EPHY_HISTORY_FILE       "ephy-history.db"
 #define EPHY_BOOKMARKS_FILE     "ephy-bookmarks.xml"
 #define EPHY_BOOKMARKS_FILE_RDF "bookmarks.rdf"
 
 int ephy_profile_utils_get_migration_version (void);
+int ephy_profile_utils_get_migration_version_for_profile_dir (const char *profile_directory);
 
 gboolean ephy_profile_utils_set_migration_version (int version);
 


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