Ticket #3684: 3684-Replace-MC_HOME-with-better-MC_PROFILE_ROOT.patch

File 3684-Replace-MC_HOME-with-better-MC_PROFILE_ROOT.patch, 5.2 KB (added by mooffie, 8 years ago)
  • lib/mcconfig.h

    From 8452246ec4461b411821719fe0032b3924943eb2 Mon Sep 17 00:00:00 2001
    From: Mooffie <mooffie@gmail.com>
    Date: Thu, 8 Sep 2016 17:02:43 +0300
    Subject: [PATCH] Replace $MC_HOME with $MC_PROFILE_ROOT, a better "profile"
     mechanism.
    
    ---
     lib/mcconfig.h       |  2 ++
     lib/mcconfig/paths.c | 57 +++++++++++++++++++++++++++++++++++++---------------
     src/textconf.c       |  3 ++-
     3 files changed, 45 insertions(+), 17 deletions(-)
    
    diff --git a/lib/mcconfig.h b/lib/mcconfig.h
    index 931342e..426822b 100644
    a b const char *mc_config_get_cache_path (void); 
    107107 
    108108const char *mc_config_get_path (void); 
    109109 
     110const char *mc_config_get_profile_root (void); 
     111 
    110112const char *mc_config_get_home_dir (void); 
    111113 
    112114char *mc_config_get_full_path (const char *config_name); 
  • lib/mcconfig/paths.c

    diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c
    index 7c34622..d2f478a 100644
    a b static char *mc_config_str = NULL; 
    5151static char *mc_cache_str = NULL; 
    5252static char *mc_data_str = NULL; 
    5353 
    54 /* value of $MC_HOME */ 
    55 static const char *mc_home = NULL; 
    56  
    5754static gboolean config_dir_present = FALSE; 
    5855 
    5956static const struct 
    mc_config_deprecated_dir_present (void) 
    282279/*** public functions ****************************************************************************/ 
    283280/* --------------------------------------------------------------------------------------------- */ 
    284281 
     282/** 
     283 * The "profile root" is the tree under which all of MC's user data & 
     284 * settings are stored. 
     285 * 
     286 * It defaults to the user's home dir. The user may override this default 
     287 * with the environment variable $MC_PROFILE_ROOT. 
     288 */ 
     289const char * 
     290mc_config_get_profile_root (void) 
     291{ 
     292    static const char *profile_root = NULL; 
     293 
     294    if (profile_root == NULL) 
     295    { 
     296        profile_root = g_getenv ("MC_PROFILE_ROOT"); 
     297        if (profile_root == NULL || *profile_root == '\0') 
     298           profile_root = mc_config_get_home_dir (); 
     299    } 
     300 
     301    return profile_root; 
     302} 
     303 
     304/* --------------------------------------------------------------------------------------------- */ 
     305 
    285306void 
    286307mc_config_init_config_paths (GError ** mcerror) 
    287308{ 
    mc_config_init_config_paths (GError ** mcerror) 
    295316    if (xdg_vars_initialized) 
    296317        return; 
    297318 
    298     /* init mc_home if not yet */ 
    299     (void) mc_config_get_home_dir (); 
    300  
    301319#if MC_HOMEDIR_XDG 
    302     if (mc_home != NULL) 
     320    if (strcmp (mc_config_get_profile_root (), mc_config_get_home_dir ()) != 0) 
    303321    { 
    304         dir = g_build_filename (mc_home, ".config", (char *) NULL); 
     322        /* 
     323         * The user overrode the default profile root. 
     324         * 
     325         * In this case we can't use GLib's g_get_user_{config,cache,data}_dir() 
     326         * as these functions use the user's home dir as the root. 
     327         */ 
     328 
     329        const char *profile_root; 
     330 
     331        profile_root = mc_config_get_profile_root (); 
     332 
     333        dir = g_build_filename (profile_root, ".config", (char *) NULL); 
    305334        mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); 
    306335        g_free (dir); 
    307336 
    308         dir = g_build_filename (mc_home, ".cache", (char *) NULL); 
     337        dir = g_build_filename (profile_root, ".cache", (char *) NULL); 
    309338        mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); 
    310339        g_free (dir); 
    311340 
    312         dir = g_build_filename (mc_home, ".local", "share", (char *) NULL); 
     341        dir = g_build_filename (profile_root, ".local", "share", (char *) NULL); 
    313342        mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); 
    314343        g_free (dir); 
    315344    } 
    mc_config_init_config_paths (GError ** mcerror) 
    331360    else 
    332361    { 
    333362        g_free (defined_userconf_dir); 
    334         dir = g_build_filename (mc_config_get_home_dir (), MC_USERCONF_DIR, (char *) NULL); 
     363        dir = g_build_filename (mc_config_get_profile_root (), MC_USERCONF_DIR, (char *) NULL); 
    335364    } 
    336365 
    337366    mc_data_str = mc_cache_str = mc_config_str = mc_config_init_one_config_path (dir, "", mcerror); 
    mc_config_get_home_dir (void) 
    393422 
    394423    if (homedir == NULL) 
    395424    { 
    396         homedir = g_getenv ("MC_HOME"); 
    397425        /* Prior to GLib 2.36, g_get_home_dir() ignores $HOME, which is why 
    398426         * we read it ourselves. As that function's documentation explains, 
    399427         * using $HOME is good for compatibility with other programs and 
    400428         * for running from test frameworks. */ 
    401         if (homedir == NULL || *homedir == '\0') 
    402             homedir = g_getenv ("HOME"); 
    403         else 
    404             mc_home = homedir; 
     429        homedir = g_getenv ("HOME"); 
    405430        if (homedir == NULL || *homedir == '\0') 
    406431            homedir = g_get_home_dir (); 
    407432    } 
  • src/textconf.c

    diff --git a/src/textconf.c b/src/textconf.c
    index b743715..736f7cb 100644
    a b show_version (void) 
    195195void 
    196196show_datadirs_extended (void) 
    197197{ 
    198     (void) printf ("%s %s\n", _("Root directory:"), mc_config_get_home_dir ()); 
     198    (void) printf ("%s %s\n", _("Home directory:"), mc_config_get_home_dir ()); 
     199    (void) printf ("%s %s\n", _("Profile root directory:"), mc_config_get_profile_root ()); 
    199200    (void) puts (""); 
    200201 
    201202    PRINTF_GROUP (_("System data"));