Merge branch '3684_mc_profile_root'

* 3684_mc_profile_root:
  (mc_config_init_config_paths): minor optimization.
  Rename mc_config_get_profile_root() to mc_get_profile_root()
  Fix manual pages.
  Ticket #3684: replace $MC_HOME with $MC_PROFILE_ROOT, a better "profile" mechanism.
This commit is contained in:
Andrew Borodin 2016-12-04 09:41:23 +03:00
commit 61c681de94
10 changed files with 66 additions and 38 deletions

View File

@ -4258,10 +4258,10 @@ personal o de sistema.
.PP .PP
Para cambiar el directorio de incio de MC se puede utilizar la variable de Para cambiar el directorio de incio de MC se puede utilizar la variable de
entorno entorno
.BR MC_HOME . .BR MC_PROFILE_ROOT .
El valor de MC_HOME tiene que ser una ruta absoluta. Si MC_HOME no existe o El valor de MC_PROFILE_ROOT tiene que ser una ruta absoluta. Si MC_PROFILE_ROOT
está vacía se usa la variable HOME. Si HOME no existe o está vacía se recurre no existe o está vacía se usa la variable HOME. Si HOME no existe o está vacía
a la biblioteca GLib para obtener los directorios de MC. se recurre a la biblioteca GLib para obtener los directorios de MC.
.\"SKIP_SECTION" .\"SKIP_SECTION"
.SH "LICENCIA" .SH "LICENCIA"
Este programa se distribuye en los términos que recoge la Licencia Pública Este programa se distribuye en los términos que recoge la Licencia Pública

View File

@ -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. használja a home, vagy rendszerszintű alkalmazás menü helyett.
.PP .PP
To change default home directory of MC, you can use To change default home directory of MC, you can use
.BR MC_HOME .BR MC_PROFILE_ROOT
environment variable. The value of MC_HOME must be an absolute path. If MC_HOME environment variable. The value of MC_PROFILE_ROOT must be an absolute path.
is unset or empty, HOME variable is used. If HOME is unset or empty, MC If MC_PROFILE_ROOT is unset or empty, HOME variable is used. If HOME is unset
directories are get from GLib library. or empty, MC directories are get from GLib library.
.\"NODE "AVAILABILITY" .\"NODE "AVAILABILITY"
.SH "A Midnight Commander frissítése" .SH "A Midnight Commander frissítése"
A program legutolsó verzióját az ftp.nuclecu.unam.mx címen a A program legutolsó verzióját az ftp.nuclecu.unam.mx címen a

View File

@ -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. al posto del menu delle applicazioni utente o di sistema.
.PP .PP
To change default home directory of MC, you can use To change default home directory of MC, you can use
.BR MC_HOME .BR MC_PROFILE_ROOT
environment variable. The value of MC_HOME must be an absolute path. If MC_HOME environment variable. The value of MC_PROFILE_ROOT must be an absolute path.
is unset or empty, HOME variable is used. If HOME is unset or empty, MC If MC_PROFILE_ROOT is unset or empty, HOME variable is used. If HOME is unset
directories are get from GLib library. or empty, MC directories are get from GLib library.
.\"SKIP_SECTION" .\"SKIP_SECTION"
.SH "LICENZA" .SH "LICENZA"
Questo programma è distribuito sotto i termini della Licenza Generale Questo programma è distribuito sotto i termini della Licenza Generale

View File

@ -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. the home or system\-wide applications menu.
.PP .PP
To change default root directory of MC, you can use To change default root directory of MC, you can use
.BR MC_HOME .BR MC_PROFILE_ROOT
environment variable. The value of MC_HOME must be an absolute path. If MC_HOME environment variable. The value of MC_PROFILE_ROOT must be an absolute path.
is unset or empty, HOME variable is used. If HOME is unset or empty, MC If MC_PROFILE_ROOT is unset or empty, HOME variable is used. If HOME is unset
directories are get from GLib library. or empty, MC directories are get from GLib library.
.\"SKIP_SECTION" .\"SKIP_SECTION"
.SH "LICENSE" .SH "LICENSE"
This program is distributed under the terms of the GNU General Public This program is distributed under the terms of the GNU General Public

View File

@ -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. jest używany zamiast pliku w katalogu domowym i ogólnosystemowego.
.PP .PP
To change default home directory of MC, you can use To change default home directory of MC, you can use
.BR MC_HOME .BR MC_PROFILE_ROOT
environment variable. The value of MC_HOME must be an absolute path. If MC_HOME environment variable. The value of MC_PROFILE_ROOT must be an absolute path.
is unset or empty, HOME variable is used. If HOME is unset or empty, MC If MC_PROFILE_ROOT is unset or empty, HOME variable is used. If HOME is unset
directories are get from GLib library. or empty, MC directories are get from GLib library.
.\"SKIP_SECTION" .\"SKIP_SECTION"
.SH LICENCJA .SH LICENCJA
Program jest dystrybuowany na zasadach licencji GNU General Public License Program jest dystrybuowany na zasadach licencji GNU General Public License

View File

@ -4727,8 +4727,8 @@ Commander; используется только в тех случаях, ко
.PP .PP
Для того, чтобы изменить корневой каталог MC, установленный по умолчанию, Для того, чтобы изменить корневой каталог MC, установленный по умолчанию,
можно использовать переменную окружения можно использовать переменную окружения
.BR MC_HOME . .BR MC_PROFILE_ROOT .
Значением этой переменный должен быть абсолютный путь. Если переменная MC_HOME Значением этой переменный должен быть абсолютный путь. Если переменная MC_PROFILE_ROOT
не определена или пуста, используется переменная окружения HOME. Если и HOME не определена или пуста, используется переменная окружения HOME. Если и HOME
не определена или пуста, каталоги MC определяются средствами библиотеки GLib. не определена или пуста, каталоги MC определяются средствами библиотеки GLib.
.\"SKIP_SECTION" .\"SKIP_SECTION"

View File

@ -51,9 +51,6 @@ static char *mc_config_str = NULL;
static char *mc_cache_str = NULL; static char *mc_cache_str = NULL;
static char *mc_data_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 gboolean config_dir_present = FALSE;
static const struct static const struct
@ -285,6 +282,7 @@ mc_config_deprecated_dir_present (void)
void void
mc_config_init_config_paths (GError ** mcerror) mc_config_init_config_paths (GError ** mcerror)
{ {
const char *profile_root;
char *dir; char *dir;
#if MC_HOMEDIR_XDG == 0 #if MC_HOMEDIR_XDG == 0
char *defined_userconf_dir; char *defined_userconf_dir;
@ -295,21 +293,27 @@ mc_config_init_config_paths (GError ** mcerror)
if (xdg_vars_initialized) if (xdg_vars_initialized)
return; return;
/* init mc_home if not yet */ profile_root = mc_get_profile_root ();
(void) mc_config_get_home_dir ();
#if MC_HOMEDIR_XDG #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); mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
g_free (dir); 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); mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
g_free (dir); 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); mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
g_free (dir); g_free (dir);
} }
@ -331,7 +335,7 @@ mc_config_init_config_paths (GError ** mcerror)
else else
{ {
g_free (defined_userconf_dir); 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); 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) if (homedir == NULL)
{ {
homedir = g_getenv ("MC_HOME");
/* Prior to GLib 2.36, g_get_home_dir() ignores $HOME, which is why /* Prior to GLib 2.36, g_get_home_dir() ignores $HOME, which is why
* we read it ourselves. As that function's documentation explains, * we read it ourselves. As that function's documentation explains,
* using $HOME is good for compatibility with other programs and * using $HOME is good for compatibility with other programs and
* for running from test frameworks. */ * for running from test frameworks. */
if (homedir == NULL || *homedir == '\0') homedir = g_getenv ("HOME");
homedir = g_getenv ("HOME");
else
mc_home = homedir;
if (homedir == NULL || *homedir == '\0') if (homedir == NULL || *homedir == '\0')
homedir = g_get_home_dir (); homedir = g_get_home_dir ();
} }

View File

@ -1418,6 +1418,30 @@ guess_message_value (void)
return g_strdup (locale); 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. * Propagate error in simple way.

View File

@ -249,6 +249,8 @@ char *guess_message_value (void);
char *mc_build_filename (const char *first_element, ...); char *mc_build_filename (const char *first_element, ...);
char *mc_build_filenamev (const char *first_element, va_list args); char *mc_build_filenamev (const char *first_element, va_list args);
const char *mc_get_profile_root (void);
/* *INDENT-OFF* */ /* *INDENT-OFF* */
void mc_propagate_error (GError ** dest, int code, const char *format, ...) G_GNUC_PRINTF (3, 4); 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); void mc_replace_error (GError ** dest, int code, const char *format, ...) G_GNUC_PRINTF (3, 4);

View File

@ -33,6 +33,7 @@
#include "lib/global.h" #include "lib/global.h"
#include "lib/fileloc.h" #include "lib/fileloc.h"
#include "lib/mcconfig.h" #include "lib/mcconfig.h"
#include "lib/util.h" /* mc_get_profile_root() */
#include "src/textconf.h" #include "src/textconf.h"
@ -180,7 +181,8 @@ show_version (void)
void void
show_datadirs_extended (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 (""); (void) puts ("");
PRINTF_GROUP (_("System data")); PRINTF_GROUP (_("System data"));