Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 3903c605c307b5548ce2b0ab1998fa0050404711 Mon Sep 17 00:00:00 2001
- From: Mooffie <mooffie@gmail.com>
- Date: Thu, 8 Sep 2016 17:02:43 +0300
- Subject: [PATCH] profile root
- ---
- lib/mcconfig/paths.c | 57 ++++++++++++++++++++++++++++++++++++++++------------
- 1 file changed, 44 insertions(+), 13 deletions(-)
- diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c
- index 7c34622..915ea56 100644
- --- a/lib/mcconfig/paths.c
- +++ b/lib/mcconfig/paths.c
- @@ -279,9 +279,43 @@ mc_config_deprecated_dir_present (void)
- }
- /* --------------------------------------------------------------------------------------------- */
- +
- +static const char *
- +mc_config_get_profile_root_override (void)
- +{
- + const char *profile_root;
- +
- + profile_root = g_getenv ("MC_PROFILE_ROOT");
- + if (profile_root != NULL && *profile_root != '\0')
- + return profile_root return NULL;
- +}
- +
- +/* --------------------------------------------------------------------------------------------- */
- /*** public functions ****************************************************************************/
- /* --------------------------------------------------------------------------------------------- */
- +/**
- + * The "profile root" is the tree under which all of MC's user data &
- + * settings are stored.
- + *
- + * It defaults to the user homedir. The user may override this default
- + * with the environment variable $MC_PROFILE_ROOT.
- + */
- +static const char *
- +mc_config_get_profile_root (void)
- +{
- + const char *profile_root_override;
- +
- + profile_root_override = mc_config_get_profile_root_override ();
- +
- + if (profile_root_override != NULL)
- + return profile_root_override;
- + else
- + return mc_config_get_home_dir ();
- +}
- +
- +/* --------------------------------------------------------------------------------------------- */
- +
- void
- mc_config_init_config_paths (GError ** mcerror)
- {
- @@ -295,21 +329,22 @@ mc_config_init_config_paths (GError ** mcerror)
- if (xdg_vars_initialized)
- return;
- - /* init mc_home if not yet */
- - (void) mc_config_get_home_dir ();
- -
- #if MC_HOMEDIR_XDG
- - if (mc_home != NULL)
- + if (mc_config_get_profile_root_override () != NULL)
- {
- - dir = g_build_filename (mc_home, ".config", (char *) NULL);
- + const char *profile_root;
- +
- + profile_root = mc_config_get_profile_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 +366,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 (mc_config_get_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 +428,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 ();
- }
- --
- 2.5.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement