diff options
Diffstat (limited to 'src/mcd-account-migrator.c')
-rw-r--r-- | src/mcd-account-migrator.c | 110 |
1 files changed, 97 insertions, 13 deletions
diff --git a/src/mcd-account-migrator.c b/src/mcd-account-migrator.c index 9fa3fe18..5a1ae94b 100644 --- a/src/mcd-account-migrator.c +++ b/src/mcd-account-migrator.c @@ -21,11 +21,15 @@ #include "config.h" +#include <errno.h> #include <string.h> #include <telepathy-glib/telepathy-glib.h> +#include <glib/gstdio.h> + #include "mcd-account-migrator.h" +#include "mcd-misc.h" typedef struct { @@ -74,6 +78,23 @@ get_account_conf_filename (const gchar *filename) return g_build_filename (base, filename, NULL); } +static gchar * +get_new_account_dir (void) +{ + return g_build_filename ( + g_get_user_config_dir (), "mission-control", "accounts", NULL); +} + +static void +create_new_account_dir (void) +{ + gchar *account_dir = get_new_account_dir (); + + g_mkdir_with_parents (account_dir, 0700); + + g_free (account_dir); +} + static GKeyFile * parse_old_accounts_cfg (void) { @@ -97,10 +118,66 @@ clear_accounts_cfg (void) /* TODO */ g_file_set_contents (filename, "# Accounts have been migrated", -1, NULL); + _mcd_chmod_private (filename); g_free (filename); } +/* man I can't wait until this file can be deleted */ +static void +move_everything_else (void) +{ + gchar *old_dir = get_account_conf_filename (NULL); + gchar *new_dir = get_new_account_dir (); + GFile *old = g_file_new_for_path (old_dir); + GFileEnumerator *enumerator; + static const gchar * const files_to_move[] = { + ".mc_connections", + NULL + }; + + enumerator = g_file_enumerate_children (old, + G_FILE_ATTRIBUTE_STANDARD_NAME, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL, NULL); + + if (enumerator != NULL) + { + GFileInfo *info; + + while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) + { + const gchar *tmp = g_file_info_get_name (info); + gchar *old_filename; + gchar *new_filename; + gint ret; + + old_filename = g_build_filename (old_dir, tmp, NULL); + new_filename = g_build_filename (new_dir, tmp, NULL); + + if (!g_file_test (old_filename, G_FILE_TEST_IS_REGULAR) + || tp_strv_contains (files_to_move, tmp)) + { + ret = g_rename (old_filename, new_filename); + + if (ret == -1) + g_warning ("failed to move directory '%s': %s", + old_filename, g_strerror (errno)); + } + + g_free (old_filename); + g_free (new_filename); + g_object_unref (info); + } + + g_object_unref (enumerator); + } + + g_object_unref (old); + g_free (old_dir); + g_free (new_dir); +} + static gboolean migrate_one_account (gpointer user_data); /* it's not you it's me */ @@ -330,9 +407,11 @@ save_new_account_file (MigrateData *data, GVariant *variant) { gchar *str = g_variant_print (variant, TRUE); - gchar *account_dir = get_account_conf_filename (NULL); + gchar *account_dir = get_new_account_dir (); gchar *filename, *tmp; + g_mkdir_with_parents (account_dir, 0700); + tmp = escape_path (*(data->current_group)); filename = g_build_filename (account_dir, tmp, NULL); g_free (tmp); @@ -341,6 +420,9 @@ save_new_account_file (MigrateData *data, if (!g_file_test (filename, G_FILE_TEST_EXISTS)) g_file_set_contents (filename, str, -1, NULL); + _mcd_chmod_private (filename); + + g_free (filename); g_free (account_dir); g_free (str); } @@ -442,21 +524,23 @@ mcd_account_migrator_do_your_thing (void) data->dbus = tp_dbus_daemon_dup (NULL); data->keyfile = parse_old_accounts_cfg (); - if (data->keyfile == NULL) - goto out; - - data->groups = g_key_file_get_groups (data->keyfile, NULL); - data->current_group = data->groups; + if (data->keyfile != NULL) + { + data->groups = g_key_file_get_groups (data->keyfile, NULL); + data->current_group = data->groups; + } - if (data->current_group == NULL) - goto out; + if (data->current_group != NULL) + { + create_new_account_dir (); - g_idle_add (migrate_one_account, data); - g_main_loop_run (data->loop); + g_idle_add (migrate_one_account, data); + g_main_loop_run (data->loop); - /* I hope it worked lolololololol */ - clear_accounts_cfg (); + /* I hope it worked lolololololol */ + clear_accounts_cfg (); + move_everything_else (); + } -out: migrate_data_free (data); } |