From 856434fe3e0620cd8fe52a696c46ad05d3b43265 Mon Sep 17 00:00:00 2001 From: William Jon McCann Date: Wed, 25 Apr 2012 21:25:11 -0400 Subject: [PATCH] Migrate accounts to use XDG config directory https://bugs.freedesktop.org/show_bug.cgi?id=35896 --- configure.ac | 2 +- src/mcd-account-manager-default.c | 16 +++++++---- src/mcd-account-manager.c | 56 +++++++++++++++++++++++++++++++++++++ src/mcd-account.c | 18 +++++++----- 4 files changed, 78 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 09896b2..090732c 100644 --- a/configure.ac +++ b/configure.ac @@ -133,7 +133,7 @@ AC_SUBST(mctestsdir) AC_ARG_WITH(accounts_dir, AS_HELP_STRING([--with-accounts-dir=],[Directory for storing accounts])) if test -z "$with_accounts_dir" ; then - ACCOUNTS_DIR="~/.mission-control/accounts" + ACCOUNTS_DIR="" else ACCOUNTS_DIR=$with_accounts_dir fi diff --git a/src/mcd-account-manager-default.c b/src/mcd-account-manager-default.c index deae163..2d1e569 100644 --- a/src/mcd-account-manager-default.c +++ b/src/mcd-account-manager-default.c @@ -343,13 +343,17 @@ get_account_conf_filename (void) if (!base) base = ACCOUNTS_DIR; - if (!base) - return NULL; - - if (base[0] == '~') - return g_build_filename (g_get_home_dir(), base + 1, "accounts.cfg", NULL); + if (base != NULL) + { + if (base[0] == '~') + return g_build_filename (g_get_home_dir(), base + 1, "accounts.cfg", NULL); + else + return g_build_filename (base, "accounts.cfg", NULL); + } else - return g_build_filename (base, "accounts.cfg", NULL); + { + return g_build_filename (g_get_user_config_dir(), "mission-control", "accounts", "accounts.cfg", NULL); + } } static void diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c index 4d93220..4b300d8 100644 --- a/src/mcd-account-manager.c +++ b/src/mcd-account-manager.c @@ -27,9 +27,13 @@ #include #include #include +#include +#include +#include #include #include #include +#include #include #include @@ -1351,6 +1355,56 @@ migrate_accounts (McdAccountManager *self, } } +static void +migrate_accounts_dir_to_xdg (void) +{ + gchar *old_dir; + gchar *new_dir; + + old_dir = g_build_filename (g_get_home_dir(), ".mission-control", "accounts", NULL); + new_dir = g_build_filename (g_get_user_config_dir(), "mission-control", "accounts", NULL); + + if (g_file_test (old_dir, G_FILE_TEST_IS_DIR) + && !g_file_test (new_dir, G_FILE_TEST_EXISTS)) + { + char *updated; + const char *message; + + /* test if we already attempted to migrate first */ + updated = g_build_filename (old_dir, "DEPRECATED-DIRECTORY", NULL); + message = "Mission Control 5.13 deprecated this directory and tried migrating " + "this configuration to ~/.config/mission-control/accounts"; + if (!g_file_test (updated, G_FILE_TEST_EXISTS)) + { + char *parent_dir; + parent_dir = g_path_get_dirname (new_dir); + if (g_mkdir_with_parents (parent_dir, 0755) == 0) + { + int fd, res; + + /* rename() works fine if the destination directory is + * empty. + */ + res = g_rename (old_dir, new_dir); + if (res == -1) + { + fd = g_creat (updated, 0600); + if (fd != -1) + { + res = write (fd, message, strlen (message)); + close (fd); + } + } + } + g_free (parent_dir); + } + g_free (updated); + } + + g_free (old_dir); + g_free (new_dir); +} + /** * _mcd_account_manager_setup: * @account_manager: the #McdAccountManager. @@ -1366,6 +1420,8 @@ _mcd_account_manager_setup (McdAccountManager *account_manager) McdLoadAccountsData *lad; gchar **accounts, **name; + migrate_accounts_dir_to_xdg (); + tp_list_connection_names (priv->dbus_daemon, list_connection_names_cb, NULL, NULL, (GObject *)account_manager); diff --git a/src/mcd-account.c b/src/mcd-account.c index 192d8d9..8a24f5e 100644 --- a/src/mcd-account.c +++ b/src/mcd-account.c @@ -676,14 +676,18 @@ get_account_data_path (McdAccountPrivate *priv) base = g_getenv ("MC_ACCOUNT_DIR"); if (!base) base = ACCOUNTS_DIR; - if (!base) - return NULL; - - if (base[0] == '~') - return g_build_filename (g_get_home_dir(), base + 1, - priv->unique_name, NULL); + if (base != NULL) + { + if (base[0] == '~') + return g_build_filename (g_get_home_dir(), base + 1, + priv->unique_name, NULL); + else + return g_build_filename (base, priv->unique_name, NULL); + } else - return g_build_filename (base, priv->unique_name, NULL); + { + return g_build_filename (g_get_user_config_dir(), "mission-control", "accounts", priv->unique_name, NULL); + } } static void -- 1.7.10