diff options
author | Xan Lopez <xan@igalia.com> | 2012-05-09 18:24:06 +0800 |
---|---|---|
committer | Xan Lopez <xan@igalia.com> | 2012-05-09 18:24:06 +0800 |
commit | dd510ece07f5e01debec5cd1605913cf7dec568d (patch) | |
tree | 12188b13f9c87a670bd2dc6813f15a60f8137558 | |
parent | f3a7c0fe44514d52f5a475e93470afea80390895 (diff) | |
download | gsoc2013-epiphany-dd510ece07f5e01debec5cd1605913cf7dec568d.tar gsoc2013-epiphany-dd510ece07f5e01debec5cd1605913cf7dec568d.tar.gz gsoc2013-epiphany-dd510ece07f5e01debec5cd1605913cf7dec568d.tar.bz2 gsoc2013-epiphany-dd510ece07f5e01debec5cd1605913cf7dec568d.tar.lz gsoc2013-epiphany-dd510ece07f5e01debec5cd1605913cf7dec568d.tar.xz gsoc2013-epiphany-dd510ece07f5e01debec5cd1605913cf7dec568d.tar.zst gsoc2013-epiphany-dd510ece07f5e01debec5cd1605913cf7dec568d.zip |
ephy-profile-migrator: migrate Web Applications to new profile location
We need to update their desktop files (they had references to the
profile directory) and the symlink of the .desktop file in the Shell
applications directory.
It would be much easier to just delete and re-add the applications,
but unfortunately that would wipe out the existing profile data in the
apps (like cookies).
-rw-r--r-- | lib/ephy-profile-migrator.c | 87 | ||||
-rw-r--r-- | lib/ephy-profile-utils.h | 2 |
2 files changed, 87 insertions, 2 deletions
diff --git a/lib/ephy-profile-migrator.c b/lib/ephy-profile-migrator.c index ac5e1846a..ab933f0ec 100644 --- a/lib/ephy-profile-migrator.c +++ b/lib/ephy-profile-migrator.c @@ -37,6 +37,7 @@ #include "ephy-history-service.h" #include "ephy-profile-utils.h" #include "ephy-settings.h" +#include "ephy-web-app-utils.h" #ifdef ENABLE_NSS #include "ephy-nss-glue.h" #endif @@ -677,6 +678,89 @@ migrate_profile_gnome2_to_xdg () g_free (old_dir); } +static char * +fix_desktop_file_and_return_new_location (const char *dir) +{ + GRegex * regex; + char *result, *old_profile_dir, *replacement, *contents, *new_contents; + gsize length; + + old_profile_dir = g_build_filename (g_get_home_dir (), + ".gnome2", + NULL); + replacement = g_build_filename (g_get_user_config_dir (), + NULL); + regex = g_regex_new (old_profile_dir, 0, 0, NULL); + + /* We want to modify both the link destination and the contents of + * the .desktop file itself. */ + result = g_regex_replace (regex, dir, -1, + 0, replacement, 0, NULL); + g_file_get_contents (result, &contents, &length, NULL); + new_contents = g_regex_replace (regex, contents, -1, 0, + replacement, 0, NULL); + g_file_set_contents (result, new_contents, length, NULL); + + g_free (contents); + g_free (new_contents); + g_free (old_profile_dir); + g_free (replacement); + + g_regex_unref (regex); + + return result; +} + +static void +migrate_web_app_links () +{ + GList *apps, *p; + + apps = ephy_web_application_get_application_list (); + for (p = apps; p; p = p->next) { + char *desktop_file, *app_link; + EphyWebApplication *app = (EphyWebApplication*)p->data; + + desktop_file = app->desktop_file; + + /* Update the link in applications. */ + app_link = g_build_filename (g_get_user_data_dir (), "applications", desktop_file, NULL); + if (g_file_test (app_link, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_SYMLINK)) { + /* Change the link to point to the new profile dir. */ + GFileInfo *info; + const char *target; + GFile *file = g_file_new_for_path (app_link); + + info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET, + 0, NULL, NULL); + if (info) { + char *new_target; + + target = g_file_info_get_symlink_target (info); + new_target = fix_desktop_file_and_return_new_location (target); + + /* FIXME: Updating the file info and setting it again should + * work, but it does not? Just delete and create the link + * again. */ + g_file_delete (file, 0, 0); + g_object_unref (file); + + file = g_file_new_for_path (app_link); + g_file_make_symbolic_link (file, new_target, NULL, NULL); + + g_object_unref (info); + g_free (new_target); + } + + g_object_unref (file); + } + + g_free (app_link); + } + + ephy_web_application_free_application_list (apps); +} + const EphyProfileMigrator migrators[] = { migrate_cookies, migrate_passwords, @@ -687,7 +771,8 @@ const EphyProfileMigrator migrators[] = { * login/passwords for page forms, which we previously ignored */ migrate_passwords2, migrate_history, - migrate_tabs_visibility + migrate_tabs_visibility, + migrate_web_app_links }; static void diff --git a/lib/ephy-profile-utils.h b/lib/ephy-profile-utils.h index 353a5605b..d26fe1ca5 100644 --- a/lib/ephy-profile-utils.h +++ b/lib/ephy-profile-utils.h @@ -26,7 +26,7 @@ #define FORM_USERNAME_KEY "form_username" #define FORM_PASSWORD_KEY "form_password" -#define EPHY_PROFILE_MIGRATION_VERSION 6 +#define EPHY_PROFILE_MIGRATION_VERSION 7 int ephy_profile_utils_get_migration_version (void); |