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



commit 8e2cf1061326cf97cca41e7999dc94327a66dada
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 6eb5d4b..59bfb52 100644
--- a/lib/ephy-profile-migrator.c
+++ b/lib/ephy-profile-migrator.c
@@ -1028,8 +1028,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 b5dbb08..e514205 100644
--- a/lib/ephy-profile-utils.c
+++ b/lib/ephy-profile-utils.c
@@ -23,17 +23,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 (void)
+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);
 
@@ -47,7 +49,8 @@ ephy_profile_utils_get_migration_version (void)
 
     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
@@ -62,6 +65,12 @@ ephy_profile_utils_get_migration_version (void)
   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 2e873c3..3e7933e 100644
--- a/lib/ephy-profile-utils.h
+++ b/lib/ephy-profile-utils.h
@@ -21,12 +21,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]