diff --git a/doc/man/es/mc.1.in b/doc/man/es/mc.1.in index 30165fdf0..2f07a0be8 100644 --- a/doc/man/es/mc.1.in +++ b/doc/man/es/mc.1.in @@ -4258,10 +4258,10 @@ personal o de sistema. .PP Para cambiar el directorio de incio de MC se puede utilizar la variable de entorno -.BR MC_HOME . -El valor de MC_HOME tiene que ser una ruta absoluta. Si MC_HOME no existe o -está vacía se usa la variable HOME. Si HOME no existe o está vacía se recurre -a la biblioteca GLib para obtener los directorios de MC. +.BR MC_PROFILE_ROOT . +El valor de MC_PROFILE_ROOT tiene que ser una ruta absoluta. Si MC_PROFILE_ROOT +no existe o está vacía se usa la variable HOME. Si HOME no existe o está vacía +se recurre a la biblioteca GLib para obtener los directorios de MC. .\"SKIP_SECTION" .SH "LICENCIA" Este programa se distribuye en los términos que recoge la Licencia Pública diff --git a/doc/man/hu/mc.1.in b/doc/man/hu/mc.1.in index 2a67463c0..229928250 100644 --- a/doc/man/hu/mc.1.in +++ b/doc/man/hu/mc.1.in @@ -3242,10 +3242,10 @@ Helyi felhasználó által definiált menü. Ha ez a fájl létezik, ezt használja a home, vagy rendszerszintű alkalmazás menü helyett. .PP To change default home directory of MC, you can use -.BR MC_HOME -environment variable. The value of MC_HOME must be an absolute path. If MC_HOME -is unset or empty, HOME variable is used. If HOME is unset or empty, MC -directories are get from GLib library. +.BR MC_PROFILE_ROOT +environment variable. The value of MC_PROFILE_ROOT must be an absolute path. +If MC_PROFILE_ROOT is unset or empty, HOME variable is used. If HOME is unset +or empty, MC directories are get from GLib library. .\"NODE "AVAILABILITY" .SH "A Midnight Commander frissítése" A program legutolsó verzióját az ftp.nuclecu.unam.mx címen a diff --git a/doc/man/it/mc.1.in b/doc/man/it/mc.1.in index e549f19ea..cbe9a2e7e 100644 --- a/doc/man/it/mc.1.in +++ b/doc/man/it/mc.1.in @@ -3231,10 +3231,10 @@ Menu locale definito dall'utente. Se questo file è presente viene usato al posto del menu delle applicazioni utente o di sistema. .PP To change default home directory of MC, you can use -.BR MC_HOME -environment variable. The value of MC_HOME must be an absolute path. If MC_HOME -is unset or empty, HOME variable is used. If HOME is unset or empty, MC -directories are get from GLib library. +.BR MC_PROFILE_ROOT +environment variable. The value of MC_PROFILE_ROOT must be an absolute path. +If MC_PROFILE_ROOT is unset or empty, HOME variable is used. If HOME is unset +or empty, MC directories are get from GLib library. .\"SKIP_SECTION" .SH "LICENZA" Questo programma è distribuito sotto i termini della Licenza Generale diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in index 1d6cb16de..b63223e86 100644 --- a/doc/man/mc.1.in +++ b/doc/man/mc.1.in @@ -4341,10 +4341,10 @@ Local user\-defined menu. If this file is present, it is used instead of the home or system\-wide applications menu. .PP To change default root directory of MC, you can use -.BR MC_HOME -environment variable. The value of MC_HOME must be an absolute path. If MC_HOME -is unset or empty, HOME variable is used. If HOME is unset or empty, MC -directories are get from GLib library. +.BR MC_PROFILE_ROOT +environment variable. The value of MC_PROFILE_ROOT must be an absolute path. +If MC_PROFILE_ROOT is unset or empty, HOME variable is used. If HOME is unset +or empty, MC directories are get from GLib library. .\"SKIP_SECTION" .SH "LICENSE" This program is distributed under the terms of the GNU General Public diff --git a/doc/man/pl/mc.1.in b/doc/man/pl/mc.1.in index 4d7018d54..89085fbf4 100644 --- a/doc/man/pl/mc.1.in +++ b/doc/man/pl/mc.1.in @@ -2939,10 +2939,10 @@ Lokalny plik zdefiniowany przez użytkownika. Jeśli ten plik jest dostępny, jest używany zamiast pliku w katalogu domowym i ogólnosystemowego. .PP To change default home directory of MC, you can use -.BR MC_HOME -environment variable. The value of MC_HOME must be an absolute path. If MC_HOME -is unset or empty, HOME variable is used. If HOME is unset or empty, MC -directories are get from GLib library. +.BR MC_PROFILE_ROOT +environment variable. The value of MC_PROFILE_ROOT must be an absolute path. +If MC_PROFILE_ROOT is unset or empty, HOME variable is used. If HOME is unset +or empty, MC directories are get from GLib library. .\"SKIP_SECTION" .SH LICENCJA Program jest dystrybuowany na zasadach licencji GNU General Public License diff --git a/doc/man/ru/mc.1.in b/doc/man/ru/mc.1.in index f50aec653..ebe017fd0 100644 --- a/doc/man/ru/mc.1.in +++ b/doc/man/ru/mc.1.in @@ -4727,8 +4727,8 @@ Commander; используется только в тех случаях, ко .PP Для того, чтобы изменить корневой каталог MC, установленный по умолчанию, можно использовать переменную окружения -.BR MC_HOME . -Значением этой переменный должен быть абсолютный путь. Если переменная MC_HOME +.BR MC_PROFILE_ROOT . +Значением этой переменный должен быть абсолютный путь. Если переменная MC_PROFILE_ROOT не определена или пуста, используется переменная окружения HOME. Если и HOME не определена или пуста, каталоги MC определяются средствами библиотеки GLib. .\"SKIP_SECTION" diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c index 7c3462234..cccdf8b39 100644 --- a/lib/mcconfig/paths.c +++ b/lib/mcconfig/paths.c @@ -51,9 +51,6 @@ static char *mc_config_str = NULL; static char *mc_cache_str = NULL; static char *mc_data_str = NULL; -/* value of $MC_HOME */ -static const char *mc_home = NULL; - static gboolean config_dir_present = FALSE; static const struct @@ -285,6 +282,7 @@ mc_config_deprecated_dir_present (void) void mc_config_init_config_paths (GError ** mcerror) { + const char *profile_root; char *dir; #if MC_HOMEDIR_XDG == 0 char *defined_userconf_dir; @@ -295,21 +293,27 @@ mc_config_init_config_paths (GError ** mcerror) if (xdg_vars_initialized) return; - /* init mc_home if not yet */ - (void) mc_config_get_home_dir (); + profile_root = mc_get_profile_root (); #if MC_HOMEDIR_XDG - if (mc_home != NULL) + if (strcmp (profile_root, mc_config_get_home_dir ()) != 0) { - dir = g_build_filename (mc_home, ".config", (char *) NULL); + /* + * The user overrode the default profile root. + * + * In this case we can't use GLib's g_get_user_{config,cache,data}_dir() + * as these functions use the user's home dir as the root. + */ + + dir = g_build_filename (profile_root, ".config", (char *) NULL); mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); g_free (dir); - dir = g_build_filename (mc_home, ".cache", (char *) NULL); + dir = g_build_filename (profile_root, ".cache", (char *) NULL); mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); g_free (dir); - dir = g_build_filename (mc_home, ".local", "share", (char *) NULL); + dir = g_build_filename (profile_root, ".local", "share", (char *) NULL); mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); g_free (dir); } @@ -331,7 +335,7 @@ mc_config_init_config_paths (GError ** mcerror) else { g_free (defined_userconf_dir); - dir = g_build_filename (mc_config_get_home_dir (), MC_USERCONF_DIR, (char *) NULL); + 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); @@ -393,15 +397,11 @@ mc_config_get_home_dir (void) if (homedir == NULL) { - homedir = g_getenv ("MC_HOME"); /* Prior to GLib 2.36, g_get_home_dir() ignores $HOME, which is why * we read it ourselves. As that function's documentation explains, * using $HOME is good for compatibility with other programs and * for running from test frameworks. */ - if (homedir == NULL || *homedir == '\0') - homedir = g_getenv ("HOME"); - else - mc_home = homedir; + homedir = g_getenv ("HOME"); if (homedir == NULL || *homedir == '\0') homedir = g_get_home_dir (); } diff --git a/lib/util.c b/lib/util.c index 304351ddd..2112e2dfe 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1418,6 +1418,30 @@ guess_message_value (void) return g_strdup (locale); } +/* --------------------------------------------------------------------------------------------- */ + +/** + * The "profile root" is the tree under which all of MC's user data & + * settings are stored. + * + * It defaults to the user's home dir. The user may override this default + * with the environment variable $MC_PROFILE_ROOT. + */ +const char * +mc_get_profile_root (void) +{ + static const char *profile_root = NULL; + + if (profile_root == NULL) + { + profile_root = g_getenv ("MC_PROFILE_ROOT"); + if (profile_root == NULL || *profile_root == '\0') + profile_root = mc_config_get_home_dir (); + } + + return profile_root; +} + /* --------------------------------------------------------------------------------------------- */ /** * Propagate error in simple way. diff --git a/lib/util.h b/lib/util.h index af4022ee7..6b986a3fd 100644 --- a/lib/util.h +++ b/lib/util.h @@ -249,6 +249,8 @@ char *guess_message_value (void); char *mc_build_filename (const char *first_element, ...); char *mc_build_filenamev (const char *first_element, va_list args); +const char *mc_get_profile_root (void); + /* *INDENT-OFF* */ void mc_propagate_error (GError ** dest, int code, const char *format, ...) G_GNUC_PRINTF (3, 4); void mc_replace_error (GError ** dest, int code, const char *format, ...) G_GNUC_PRINTF (3, 4); diff --git a/src/textconf.c b/src/textconf.c index d6ee6717e..d48f17e44 100644 --- a/src/textconf.c +++ b/src/textconf.c @@ -33,6 +33,7 @@ #include "lib/global.h" #include "lib/fileloc.h" #include "lib/mcconfig.h" +#include "lib/util.h" /* mc_get_profile_root() */ #include "src/textconf.h" @@ -180,7 +181,8 @@ show_version (void) void show_datadirs_extended (void) { - (void) printf ("%s %s\n", _("Root directory:"), mc_config_get_home_dir ()); + (void) printf ("%s %s\n", _("Home directory:"), mc_config_get_home_dir ()); + (void) printf ("%s %s\n", _("Profile root directory:"), mc_get_profile_root ()); (void) puts (""); PRINTF_GROUP (_("System data"));