lib/mcconfig/paths.c: cleanup.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Andrew Borodin 2011-07-07 10:36:56 +04:00 committed by Slava Zanko
parent c057627979
commit 8ff0da42cd

View File

@ -30,9 +30,11 @@
#include <errno.h>
#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;
}