From e919c9724f612270053683ad110ffd68de135c60 Mon Sep 17 00:00:00 2001 From: Lucian Langa Date: Mon, 2 Aug 2010 19:47:30 -0400 Subject: Bug 625761 - Folder views not preserved after migration --- shell/e-shell-migrate.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 4 deletions(-) (limited to 'shell/e-shell-migrate.c') diff --git a/shell/e-shell-migrate.c b/shell/e-shell-migrate.c index f47a5e7694..8986c11201 100644 --- a/shell/e-shell-migrate.c +++ b/shell/e-shell-migrate.c @@ -38,7 +38,6 @@ #define GCONF_LAST_VERSION_KEY "/apps/evolution/last_version" /******************** Begin XDG Base Directory Migration ********************/ - /* These are the known EShellBackend names as of Evolution 3.0 */ static const gchar *shell_backend_names[] = { "addressbook", "calendar", "mail", "memos", "tasks", NULL }; @@ -61,7 +60,7 @@ shell_xdg_migrate_rename (const gchar *old_filename, g_print (" mv %s %s\n", old_filename, new_filename); - /* It's safe to go ahead and move directories because rename() + /* It's safe to go ahead and move directories because rename () * will fail if the new directory already exists with content. * With regular files we have to be careful not to overwrite * new files with old files. */ @@ -78,6 +77,7 @@ shell_xdg_migrate_rename (const gchar *old_filename, return success; } + static gboolean shell_xdg_migrate_rmdir (const gchar *dirname) { @@ -136,6 +136,78 @@ shell_xdg_migrate_process_corrections (GHashTable *corrections) } } +static gboolean +shell_xdg_migrate_rename_files (const gchar *src_directory, + const gchar *dst_directory) +{ + GDir *dir; + GHashTable *corrections; + const gchar *basename; + const gchar *home_dir; + gchar *old_base_dir; + gchar *new_base_dir; + + dir = g_dir_open (src_directory, 0, NULL); + if (dir == NULL) + return FALSE; + + /* This is to avoid renaming files which we're iterating over the + * directory. POSIX says the outcome of that is unspecified. */ + corrections = g_hash_table_new_full ( + g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) g_free); + + g_mkdir_with_parents (dst_directory, 0700); + + home_dir = g_get_home_dir (); + old_base_dir = g_build_filename (home_dir, ".evolution", NULL); + e_filename_make_safe (old_base_dir); + new_base_dir = g_strdup (e_get_user_data_dir ()); + e_filename_make_safe (new_base_dir); + + while ((basename = g_dir_read_name (dir)) != NULL) { + GString *buffer; + gchar *old_filename; + gchar *new_filename; + gchar *cp; + + buffer = g_string_new (basename); + + if ((cp = strstr (basename, old_base_dir)) != NULL) { + g_string_erase ( + buffer, cp - basename, + strlen (old_base_dir)); + g_string_insert ( + buffer, cp - basename, new_base_dir); + } + + old_filename = g_build_filename ( + src_directory, basename, NULL); + new_filename = g_build_filename ( + dst_directory, buffer->str, NULL); + + g_string_free (buffer, TRUE); + + g_hash_table_insert (corrections, old_filename, new_filename); + } + + g_free (old_base_dir); + g_free (new_base_dir); + + g_dir_close (dir); + + shell_xdg_migrate_process_corrections (corrections); + g_hash_table_destroy (corrections); + + /* It's tempting to want to remove the source directory here. + * Don't. We might be iterating over the source directory's + * parent directory, and removing the source directory would + * screw up the iteration. */ + + return TRUE; +} + static gboolean shell_xdg_migrate_move_contents (const gchar *src_directory, const gchar *dst_directory) @@ -237,7 +309,7 @@ shell_xdg_migrate_config_dir_common (EShell *shell, old_filename = g_build_filename (old_config_dir, "views", NULL); new_filename = g_build_filename (new_config_dir, "views", NULL); - shell_xdg_migrate_rename (old_filename, new_filename); + shell_xdg_migrate_rename_files (old_filename, new_filename); g_free (old_filename); g_free (new_filename); @@ -353,7 +425,7 @@ shell_xdg_migrate_config_dir_mail (EShell *shell, * threads. Rename this directory to "folders". */ old_filename = g_build_filename (old_config_dir, "config", NULL); new_filename = g_build_filename (new_config_dir, "folders", NULL); - shell_xdg_migrate_rename (old_filename, new_filename); + shell_xdg_migrate_rename_files (old_filename, new_filename); g_free (old_filename); g_free (new_filename); -- cgit v1.2.3