mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 10:04:32 +03:00
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:
parent
c057627979
commit
8ff0da42cd
@ -30,9 +30,11 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
#include "lib/mcconfig.h"
|
|
||||||
#include "lib/fileloc.h"
|
#include "lib/fileloc.h"
|
||||||
#include "lib/vfs/vfs.h"
|
#include "lib/vfs/vfs.h"
|
||||||
|
#include "lib/util.h.h" /* unix_error_string() */
|
||||||
|
|
||||||
|
#include "lib/mcconfig.h"
|
||||||
|
|
||||||
/*** global variables ****************************************************************************/
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
@ -142,7 +144,6 @@ mc_config_get_deprecated_path (void)
|
|||||||
static void
|
static void
|
||||||
mc_config_copy (const char *old_name, const char *new_name, GError ** error)
|
mc_config_copy (const char *old_name, const char *new_name, GError ** error)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (g_file_test (old_name, G_FILE_TEST_IS_REGULAR))
|
if (g_file_test (old_name, G_FILE_TEST_IS_REGULAR))
|
||||||
{
|
{
|
||||||
char *contents = NULL;
|
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,
|
g_error_new (MC_ERROR, 0,
|
||||||
_
|
_
|
||||||
("An error occured while migrating user settings: %s"),
|
("An error occured while migrating user settings: %s"),
|
||||||
g_strerror (errno)));
|
unix_error_string (errno)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((dir_name = g_dir_read_name (dir)) != NULL)
|
while ((dir_name = g_dir_read_name (dir)) != NULL)
|
||||||
{
|
{
|
||||||
char *old_name2, *new_name2;
|
char *old_name2, *new_name2;
|
||||||
|
|
||||||
old_name2 = g_build_filename (old_name, dir_name, NULL);
|
old_name2 = g_build_filename (old_name, dir_name, NULL);
|
||||||
new_name2 = g_build_filename (new_name, dir_name, NULL);
|
new_name2 = g_build_filename (new_name, dir_name, NULL);
|
||||||
mc_config_copy (old_name2, new_name2, error);
|
mc_config_copy (old_name2, new_name2, error);
|
||||||
@ -305,47 +307,36 @@ mc_config_get_path (void)
|
|||||||
void
|
void
|
||||||
mc_config_migrate_from_old_place (GError ** error)
|
mc_config_migrate_from_old_place (GError ** error)
|
||||||
{
|
{
|
||||||
char *old_dir, *tmp_dir_name;
|
char *old_dir;
|
||||||
size_t rule_index;
|
size_t rule_index;
|
||||||
|
|
||||||
old_dir = mc_config_get_deprecated_path ();
|
old_dir = mc_config_get_deprecated_path ();
|
||||||
|
|
||||||
tmp_dir_name = mc_config_init_one_config_path (xdg_config, EDIT_DIR, error);
|
g_free (mc_config_init_one_config_path (xdg_config, EDIT_DIR, error));
|
||||||
g_free (tmp_dir_name);
|
g_free (mc_config_init_one_config_path (xdg_cache, EDIT_DIR, error));
|
||||||
tmp_dir_name = mc_config_init_one_config_path (xdg_cache, EDIT_DIR, error);
|
g_free (mc_config_init_one_config_path (xdg_data, 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);
|
|
||||||
|
|
||||||
for (rule_index = 0; mc_config_migrate_rules[rule_index].old_filename != NULL; rule_index++)
|
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 =
|
old_name =
|
||||||
g_build_filename (old_dir, mc_config_migrate_rules[rule_index].old_filename, NULL);
|
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);
|
char *new_name;
|
||||||
continue;
|
|
||||||
|
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);
|
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_propagate_error (error,
|
||||||
g_error_new (MC_ERROR, 0,
|
g_error_new (MC_ERROR, 0,
|
||||||
_
|
_
|
||||||
@ -363,9 +354,13 @@ mc_config_migrate_from_old_place (GError ** error)
|
|||||||
gboolean
|
gboolean
|
||||||
mc_config_deprecated_dir_present (void)
|
mc_config_deprecated_dir_present (void)
|
||||||
{
|
{
|
||||||
char *old_dir = mc_config_get_deprecated_path ();
|
char *old_dir;
|
||||||
gboolean is_present = g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_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);
|
g_free (old_dir);
|
||||||
|
|
||||||
return is_present && !config_dir_present;
|
return is_present && !config_dir_present;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user