From c0576279799fecac111f361deec7cdcc5920a651 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 6 Jul 2011 17:07:18 +0300 Subject: [PATCH 1/2] Ticket #1851: Home config directory [xdg-user-dirs] Fixed migrating user config files. Signed-off-by: Slava Zanko --- lib/mcconfig/paths.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c index 3fdd3c57e..eb43347d6 100644 --- a/lib/mcconfig/paths.c +++ b/lib/mcconfig/paths.c @@ -142,10 +142,8 @@ mc_config_get_deprecated_path (void) static void mc_config_copy (const char *old_name, const char *new_name, GError ** error) { - if (error != NULL && *error != NULL) - return; - if (g_file_test (old_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) + if (g_file_test (old_name, G_FILE_TEST_IS_REGULAR)) { char *contents = NULL; size_t length; @@ -157,7 +155,7 @@ mc_config_copy (const char *old_name, const char *new_name, GError ** error) return; } - if (g_file_test (old_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) + if (g_file_test (old_name, G_FILE_TEST_IS_DIR)) { GDir *dir; @@ -167,7 +165,7 @@ mc_config_copy (const char *old_name, const char *new_name, GError ** error) if (dir == NULL) return; - if (!g_mkdir_with_parents (new_name, 0700)) + if (g_mkdir_with_parents (new_name, 0700) == -1) { g_dir_close (dir); g_propagate_error (error, @@ -188,15 +186,6 @@ mc_config_copy (const char *old_name, const char *new_name, GError ** error) g_free (old_name2); } } - - if (rename (old_name, new_name) != 0) - { - g_propagate_error (error, - g_error_new (MC_ERROR, 0, - _ - ("An error occured while migrating user settings: %s"), - g_strerror (errno))); - } } /* --------------------------------------------------------------------------------------------- */ From 8ff0da42cdedb9cefd641d838e197506a840b3c2 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 7 Jul 2011 10:36:56 +0400 Subject: [PATCH 2/2] lib/mcconfig/paths.c: cleanup. Signed-off-by: Andrew Borodin Signed-off-by: Slava Zanko --- lib/mcconfig/paths.c | 57 ++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c index eb43347d6..a87ccf796 100644 --- a/lib/mcconfig/paths.c +++ b/lib/mcconfig/paths.c @@ -30,9 +30,11 @@ #include #include "lib/global.h" -#include "lib/mcconfig.h" #include "lib/fileloc.h" #include "lib/vfs/vfs.h" +#include "lib/util.h.h" /* unix_error_string() */ + +#include "lib/mcconfig.h" /*** global variables ****************************************************************************/ @@ -142,7 +144,6 @@ mc_config_get_deprecated_path (void) static void mc_config_copy (const char *old_name, const char *new_name, GError ** error) { - if (g_file_test (old_name, G_FILE_TEST_IS_REGULAR)) { char *contents = NULL; @@ -172,13 +173,14 @@ mc_config_copy (const char *old_name, const char *new_name, GError ** error) g_error_new (MC_ERROR, 0, _ ("An error occured while migrating user settings: %s"), - g_strerror (errno))); + unix_error_string (errno))); return; } while ((dir_name = g_dir_read_name (dir)) != NULL) { char *old_name2, *new_name2; + old_name2 = g_build_filename (old_name, dir_name, NULL); new_name2 = g_build_filename (new_name, dir_name, NULL); mc_config_copy (old_name2, new_name2, error); @@ -305,47 +307,36 @@ mc_config_get_path (void) void mc_config_migrate_from_old_place (GError ** error) { - char *old_dir, *tmp_dir_name; + char *old_dir; size_t rule_index; old_dir = mc_config_get_deprecated_path (); - tmp_dir_name = mc_config_init_one_config_path (xdg_config, EDIT_DIR, error); - g_free (tmp_dir_name); - tmp_dir_name = mc_config_init_one_config_path (xdg_cache, EDIT_DIR, error); - g_free (tmp_dir_name); - tmp_dir_name = mc_config_init_one_config_path (xdg_data, EDIT_DIR, error); - g_free (tmp_dir_name); + g_free (mc_config_init_one_config_path (xdg_config, EDIT_DIR, error)); + g_free (mc_config_init_one_config_path (xdg_cache, EDIT_DIR, error)); + g_free (mc_config_init_one_config_path (xdg_data, EDIT_DIR, error)); for (rule_index = 0; mc_config_migrate_rules[rule_index].old_filename != NULL; rule_index++) { - char *old_name, *new_name; + char *old_name; old_name = g_build_filename (old_dir, mc_config_migrate_rules[rule_index].old_filename, NULL); - if (!g_file_test (old_name, G_FILE_TEST_EXISTS)) + if (g_file_test (old_name, G_FILE_TEST_EXISTS)) { - g_free (old_name); - continue; + char *new_name; + + new_name = g_build_filename (*mc_config_migrate_rules[rule_index].new_basedir, + mc_config_migrate_rules[rule_index].new_filename, NULL); + + mc_config_copy (old_name, new_name, error); + + g_free (new_name); } - - new_name = g_build_filename (*mc_config_migrate_rules[rule_index].new_basedir, - mc_config_migrate_rules[rule_index].new_filename, NULL); - - mc_config_copy (old_name, new_name, error); - - g_free (new_name); g_free (old_name); } - /* - { - char *old_dir2; - old_dir2 = g_strconcat (old_dir, "~", NULL); - rename (old_dir, old_dir2); - g_free (old_dir2); - } - */ + g_propagate_error (error, g_error_new (MC_ERROR, 0, _ @@ -363,9 +354,13 @@ mc_config_migrate_from_old_place (GError ** error) gboolean mc_config_deprecated_dir_present (void) { - char *old_dir = mc_config_get_deprecated_path (); - gboolean is_present = g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR); + char *old_dir; + gboolean is_present; + + old_dir = mc_config_get_deprecated_path (); + is_present = g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR); g_free (old_dir); + return is_present && !config_dir_present; }