Ticket #3682: drop automatic migration of configuration

...from ~/.mc to XDG-base.

Now MC ignores ~/.mc directory and uses XDG-based only.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2021-02-07 16:14:43 +03:00
parent c580c4bad6
commit 285eb5c186
5 changed files with 30 additions and 307 deletions

View File

@ -399,43 +399,6 @@ AC_ARG_ENABLE([mclib],
AM_CONDITIONAL([ENABLE_MCLIB], [test x$enable_mclib = xyes])
dnl ############################################################################
dnl Where config files should be placed
dnl ############################################################################
AC_ARG_WITH([homedir],
AS_HELP_STRING([--with-homedir],
[Choose any place of user settings relative to home dir, or XDG for respect XDG standards @<:@XDG@:>@]),
[
dnl Unfortunately, there is no way to tell AC_ARG_WITH that the
dnl argument value is required, so we can't differentiate
dnl between `--with-homedir` and `--with-homedir=yes`, because
dnl `with_homedir` is set to `yes` in both cases.
dnl
dnl We opt to set `with_homedir` to `.mc` if the value is `yes`
dnl in order to avoid the surprise for users using
dnl `--with-homedir` w/o any value and then getting mc to store
dnl settings in the `yes` directory.
if test "x$withval" = "xXDG"; then
with_homedir=XDG
elif test "x$withval" = "xyes"; then
with_homedir=.mc
else
with_homedir=$withval
fi
],
[with_homedir=XDG])
if test x$with_homedir = xXDG; then
AC_DEFINE(MC_HOMEDIR_XDG, 1, [Define to enable XDG standard support])
else
AC_DEFINE(MC_HOMEDIR_XDG, 0, [Define to disable XDG standard support])
AC_DEFINE_UNQUOTED([MC_USERCONF_DIR], ["$with_homedir"], [Where configs will be placed relative to $HOME])
fi
dnl ############################################################################
dnl MC options
dnl ############################################################################

View File

@ -101,8 +101,6 @@ const char *mc_config_get_path (void);
char *mc_config_get_full_path (const char *config_name);
vfs_path_t *mc_config_get_full_vpath (const char *config_name);
gboolean mc_config_migrate_from_old_place (GError ** mcerror, char **msg);
/* mcconfig/history.h */
/* read history to the mc_config, but don't save config to file */

View File

@ -40,8 +40,6 @@
/*** file scope macro definitions ****************************************************************/
#define MC_OLD_USERCONF_DIR ".mc"
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
@ -55,73 +53,46 @@ static gboolean config_dir_present = FALSE;
static const struct
{
const char *old_filename;
char **new_basedir;
const char *new_filename;
char **basedir;
const char *filename;
} mc_config_files_reference[] =
{
/* *INDENT-OFF* */
/* config */
{ "ini", &mc_config_str, MC_CONFIG_FILE },
{ "filehighlight.ini", &mc_config_str, MC_FHL_INI_FILE },
{ "hotlist", &mc_config_str, MC_HOTLIST_FILE },
{ "mc.keymap", &mc_config_str, GLOBAL_KEYMAP_FILE },
{ "menu", &mc_config_str, MC_USERMENU_FILE },
{ "cedit" PATH_SEP_STR "Syntax", &mc_config_str, EDIT_HOME_SYNTAX_FILE },
{ "cedit" PATH_SEP_STR "menu", &mc_config_str, EDIT_HOME_MENU },
{ "panels.ini", &mc_config_str, MC_PANELS_FILE },
{ &mc_config_str, MC_CONFIG_FILE },
{ &mc_config_str, MC_FHL_INI_FILE },
{ &mc_config_str, MC_HOTLIST_FILE },
{ &mc_config_str, GLOBAL_KEYMAP_FILE },
{ &mc_config_str, MC_USERMENU_FILE },
{ &mc_config_str, EDIT_HOME_SYNTAX_FILE },
{ &mc_config_str, EDIT_HOME_MENU },
{ &mc_config_str, MC_PANELS_FILE },
/* User should move this file with applying some changes in file */
{ "", &mc_config_str, MC_FILEBIND_FILE },
{ &mc_config_str, MC_FILEBIND_FILE },
/* data */
{ "skins", &mc_data_str, MC_SKINS_DIR },
{ "fish", &mc_data_str, FISH_PREFIX },
{ "ashrc", &mc_data_str, "ashrc" },
{ "bashrc", &mc_data_str, "bashrc" },
{ "inputrc", &mc_data_str, "inputrc" },
{ "extfs.d", &mc_data_str, MC_EXTFS_DIR },
{ "history", &mc_data_str, MC_HISTORY_FILE },
{ "filepos", &mc_data_str, MC_FILEPOS_FILE },
{ "cedit" PATH_SEP_STR "cooledit.clip", &mc_data_str, EDIT_HOME_CLIP_FILE },
{ "", &mc_data_str, MC_MACRO_FILE },
{ &mc_data_str, MC_SKINS_DIR },
{ &mc_data_str, FISH_PREFIX },
{ &mc_data_str, "ashrc" },
{ &mc_data_str, "bashrc" },
{ &mc_data_str, "inputrc" },
{ &mc_data_str, MC_EXTFS_DIR },
{ &mc_data_str, MC_HISTORY_FILE },
{ &mc_data_str, MC_FILEPOS_FILE },
{ &mc_data_str, EDIT_HOME_CLIP_FILE },
{ &mc_data_str, MC_MACRO_FILE },
/* cache */
{ "log", &mc_cache_str, "mc.log" },
{ "Tree", &mc_cache_str, MC_TREESTORE_FILE },
{ "cedit" PATH_SEP_STR "cooledit.temp", &mc_cache_str, EDIT_HOME_TEMP_FILE },
{ "cedit" PATH_SEP_STR "cooledit.block", &mc_cache_str, EDIT_HOME_BLOCK_FILE },
{ &mc_cache_str, "mc.log" },
{ &mc_cache_str, MC_TREESTORE_FILE },
{ &mc_cache_str, EDIT_HOME_TEMP_FILE },
{ &mc_cache_str, EDIT_HOME_BLOCK_FILE },
{NULL, NULL, NULL}
{ NULL, NULL }
/* *INDENT-ON* */
};
#if MC_HOMEDIR_XDG
static const struct
{
char **old_basedir;
const char *filename;
char **new_basedir;
} mc_config_migrate_rules_fix[] =
{
/* *INDENT-OFF* */
{ &mc_data_str, MC_USERMENU_FILE, &mc_config_str },
{ &mc_data_str, MC_FILEBIND_FILE, &mc_config_str },
{ &mc_data_str, EDIT_HOME_SYNTAX_FILE, &mc_config_str },
{ &mc_data_str, EDIT_HOME_MENU, &mc_config_str },
{ &mc_cache_str, MC_PANELS_FILE, &mc_config_str },
{ &mc_cache_str, MC_HISTORY_FILE, &mc_data_str },
{ &mc_cache_str, MC_FILEPOS_FILE, &mc_data_str },
{ &mc_cache_str, EDIT_HOME_CLIP_FILE, &mc_data_str },
{ NULL, NULL, NULL }
/* *INDENT-ON* */
};
#endif /* MC_HOMEDIR_XDG */
/* --------------------------------------------------------------------------------------------- */
/*** file scope functions *********************************************************************** */
/* --------------------------------------------------------------------------------------------- */
@ -165,111 +136,6 @@ mc_config_init_one_config_path (const char *path_base, const char *subdir, GErro
return full_path;
}
/* --------------------------------------------------------------------------------------------- */
static char *
mc_config_get_deprecated_path (void)
{
return g_build_filename (mc_config_get_home_dir (), MC_OLD_USERCONF_DIR, (char *) NULL);
}
/* --------------------------------------------------------------------------------------------- */
static void
mc_config_copy (const char *old_name, const char *new_name, GError ** mcerror)
{
mc_return_if_error (mcerror);
if (g_file_test (old_name, G_FILE_TEST_IS_REGULAR))
{
char *contents = NULL;
size_t length;
if (g_file_get_contents (old_name, &contents, &length, mcerror))
g_file_set_contents (new_name, contents, length, mcerror);
g_free (contents);
return;
}
if (g_file_test (old_name, G_FILE_TEST_IS_DIR))
{
GDir *dir;
const char *dir_name;
dir = g_dir_open (old_name, 0, mcerror);
if (dir == NULL)
return;
if (g_mkdir_with_parents (new_name, 0700) == -1)
{
g_dir_close (dir);
mc_propagate_error (mcerror, 0,
_("An error occurred while migrating user settings: %s"),
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, (char *) NULL);
new_name2 = g_build_filename (new_name, dir_name, (char *) NULL);
mc_config_copy (old_name2, new_name2, mcerror);
g_free (new_name2);
g_free (old_name2);
}
}
}
/* --------------------------------------------------------------------------------------------- */
#if MC_HOMEDIR_XDG
static void
mc_config_fix_migrated_rules (void)
{
size_t rule_index;
for (rule_index = 0; mc_config_migrate_rules_fix[rule_index].old_basedir != NULL; rule_index++)
{
char *old_name;
old_name =
g_build_filename (*mc_config_migrate_rules_fix[rule_index].old_basedir,
mc_config_migrate_rules_fix[rule_index].filename, (char *) NULL);
if (g_file_test (old_name, G_FILE_TEST_EXISTS))
{
char *new_name;
const char *basedir = *mc_config_migrate_rules_fix[rule_index].new_basedir;
const char *filename = mc_config_migrate_rules_fix[rule_index].filename;
new_name = g_build_filename (basedir, filename, (char *) NULL);
rename (old_name, new_name);
g_free (new_name);
}
g_free (old_name);
}
}
#endif /* MC_HOMEDIR_XDG */
/* --------------------------------------------------------------------------------------------- */
static gboolean
mc_config_deprecated_dir_present (void)
{
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;
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
@ -279,9 +145,6 @@ mc_config_init_config_paths (GError ** mcerror)
{
const char *profile_root;
char *dir;
#if MC_HOMEDIR_XDG == 0
char *defined_userconf_dir;
#endif
mc_return_if_error (mcerror);
@ -290,7 +153,6 @@ mc_config_init_config_paths (GError ** mcerror)
profile_root = mc_get_profile_root ();
#if MC_HOMEDIR_XDG
if (strcmp (profile_root, mc_config_get_home_dir ()) != 0)
{
/*
@ -322,22 +184,6 @@ mc_config_init_config_paths (GError ** mcerror)
mc_config_init_one_config_path (g_get_user_data_dir (), MC_USERCONF_DIR, mcerror);
}
mc_config_fix_migrated_rules ();
#else /* MC_HOMEDIR_XDG */
defined_userconf_dir = tilde_expand (MC_USERCONF_DIR);
if (g_path_is_absolute (defined_userconf_dir))
dir = defined_userconf_dir;
else
{
g_free (defined_userconf_dir);
dir = g_build_filename (profile_root, MC_USERCONF_DIR, (char *) NULL);
}
mc_data_str = mc_cache_str = mc_config_str = mc_config_init_one_config_path (dir, "", mcerror);
g_free (dir);
#endif /* MC_HOMEDIR_XDG */
xdg_vars_initialized = TRUE;
}
@ -350,10 +196,8 @@ mc_config_deinit_config_paths (void)
return;
g_free (mc_config_str);
#if MC_HOMEDIR_XDG
g_free (mc_cache_str);
g_free (mc_data_str);
#endif /* MC_HOMEDIR_XDG */
g_free (mc_global.share_data_dir);
g_free (mc_global.sysconfig_dir);
@ -415,70 +259,6 @@ mc_config_get_path (void)
return (const char *) mc_config_str;
}
/* --------------------------------------------------------------------------------------------- */
gboolean
mc_config_migrate_from_old_place (GError ** mcerror, char **msg)
{
char *old_dir;
size_t rule_index;
mc_return_val_if_error (mcerror, FALSE);
if (!mc_config_deprecated_dir_present ())
return FALSE;
old_dir = mc_config_get_deprecated_path ();
g_free (mc_config_init_one_config_path (mc_config_str, EDIT_HOME_DIR, mcerror));
#if MC_HOMEDIR_XDG
g_free (mc_config_init_one_config_path (mc_cache_str, EDIT_HOME_DIR, mcerror));
g_free (mc_config_init_one_config_path (mc_data_str, EDIT_HOME_DIR, mcerror));
#endif /* MC_HOMEDIR_XDG */
mc_return_val_if_error (mcerror, FALSE);
for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++)
{
char *old_name;
if (*mc_config_files_reference[rule_index].old_filename == '\0')
continue;
old_name =
g_build_filename (old_dir, mc_config_files_reference[rule_index].old_filename,
(char *) NULL);
if (g_file_test (old_name, G_FILE_TEST_EXISTS))
{
char *new_name;
const char *basedir = *mc_config_files_reference[rule_index].new_basedir;
const char *filename = mc_config_files_reference[rule_index].new_filename;
new_name = g_build_filename (basedir, filename, (char *) NULL);
mc_config_copy (old_name, new_name, mcerror);
g_free (new_name);
}
g_free (old_name);
}
#if MC_HOMEDIR_XDG
*msg = g_strdup_printf (_("Your old settings were migrated from %s\n"
"to Freedesktop recommended dirs.\n"
"To get more info, please visit\n"
"http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html"),
old_dir);
#else /* MC_HOMEDIR_XDG */
*msg = g_strdup_printf (_("Your old settings were migrated from %s\n"
"to %s\n"), old_dir, mc_config_str);
#endif /* MC_HOMEDIR_XDG */
g_free (old_dir);
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Get full path to config file by short name.
@ -498,11 +278,10 @@ mc_config_get_full_path (const char *config_name)
if (!xdg_vars_initialized)
mc_config_init_config_paths (NULL);
for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++)
if (strcmp (config_name, mc_config_files_reference[rule_index].new_filename) == 0)
return g_build_filename (*mc_config_files_reference[rule_index].new_basedir,
mc_config_files_reference[rule_index].new_filename,
(char *) NULL);
for (rule_index = 0; mc_config_files_reference[rule_index].filename != NULL; rule_index++)
if (strcmp (config_name, mc_config_files_reference[rule_index].filename) == 0)
return g_build_filename (*mc_config_files_reference[rule_index].basedir,
mc_config_files_reference[rule_index].filename, (char *) NULL);
return NULL;
}

View File

@ -248,8 +248,6 @@ int
main (int argc, char *argv[])
{
GError *mcerror = NULL;
gboolean config_migrated = FALSE;
char *config_migrate_msg = NULL;
int exit_code = EXIT_FAILURE;
mc_global.run_from_parent_mc = !check_sid ();
@ -298,7 +296,6 @@ main (int argc, char *argv[])
goto startup_exit_falure;
mc_config_init_config_paths (&mcerror);
config_migrated = mc_config_migrate_from_old_place (&mcerror, &config_migrate_msg);
if (mcerror != NULL)
{
mc_event_deinit (NULL);
@ -448,12 +445,6 @@ main (int argc, char *argv[])
/* subshell_prompt is NULL here */
mc_prompt = (geteuid () == 0) ? "# " : "$ ";
if (config_migrated)
{
message (D_ERROR, _("Warning"), "%s", config_migrate_msg);
g_free (config_migrate_msg);
}
}
/* Program main loop */

View File

@ -37,15 +37,9 @@
#define HOME_DIR "/home/testuser"
#if MC_HOMEDIR_XDG
#define CONF_MAIN HOME_DIR PATH_SEP_STR ".config"
#define CONF_DATA HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
#define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
#else
#define CONF_MAIN HOME_DIR
#define CONF_DATA CONF_MAIN
#define CONF_CACHE CONF_MAIN
#endif
/* --------------------------------------------------------------------------------------------- */
@ -54,11 +48,9 @@ static void
setup (void)
{
g_setenv ("HOME", HOME_DIR, TRUE);
#if MC_HOMEDIR_XDG
g_setenv ("XDG_CONFIG_HOME", CONF_MAIN, TRUE);
g_setenv ("XDG_DATA_HOME", CONF_DATA, TRUE);
g_setenv ("XDG_CACHE_HOME", CONF_CACHE, TRUE);
#endif
str_init_strings ("UTF-8");
vfs_init ();
vfs_init_localfs ();