daily pastebin goal
70%
SHARE
TWEET

mc-profile-root.patch

a guest Sep 8th, 2016 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From 3903c605c307b5548ce2b0ab1998fa0050404711 Mon Sep 17 00:00:00 2001
  2. From: Mooffie <mooffie@gmail.com>
  3. Date: Thu, 8 Sep 2016 17:02:43 +0300
  4. Subject: [PATCH] profile root
  5.  
  6. ---
  7. lib/mcconfig/paths.c | 57 ++++++++++++++++++++++++++++++++++++++++------------
  8.  1 file changed, 44 insertions(+), 13 deletions(-)
  9.  
  10. diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c
  11. index 7c34622..915ea56 100644
  12. --- a/lib/mcconfig/paths.c
  13. +++ b/lib/mcconfig/paths.c
  14. @@ -279,9 +279,43 @@ mc_config_deprecated_dir_present (void)
  15.  }
  16.  
  17.  /* --------------------------------------------------------------------------------------------- */
  18. +
  19. +static const char *
  20. +mc_config_get_profile_root_override (void)
  21. +{
  22. +    const char *profile_root;
  23. +
  24. +    profile_root = g_getenv ("MC_PROFILE_ROOT");
  25. +    if (profile_root != NULL && *profile_root != '\0')
  26. +        return profile_root return NULL;
  27. +}
  28. +
  29. +/* --------------------------------------------------------------------------------------------- */
  30.  /*** public functions ****************************************************************************/
  31.  /* --------------------------------------------------------------------------------------------- */
  32.  
  33. +/**
  34. + * The "profile root" is the tree under which all of MC's user data &
  35. + * settings are stored.
  36. + *
  37. + * It defaults to the user homedir. The user may override this default
  38. + * with the environment variable $MC_PROFILE_ROOT.
  39. + */
  40. +static const char *
  41. +mc_config_get_profile_root (void)
  42. +{
  43. +    const char *profile_root_override;
  44. +
  45. +    profile_root_override = mc_config_get_profile_root_override ();
  46. +
  47. +    if (profile_root_override != NULL)
  48. +        return profile_root_override;
  49. +    else
  50. +        return mc_config_get_home_dir ();
  51. +}
  52. +
  53. +/* --------------------------------------------------------------------------------------------- */
  54. +
  55.  void
  56.  mc_config_init_config_paths (GError ** mcerror)
  57.  {
  58. @@ -295,21 +329,22 @@ mc_config_init_config_paths (GError ** mcerror)
  59.      if (xdg_vars_initialized)
  60.          return;
  61.  
  62. -    /* init mc_home if not yet */
  63. -    (void) mc_config_get_home_dir ();
  64. -
  65.  #if MC_HOMEDIR_XDG
  66. -    if (mc_home != NULL)
  67. +    if (mc_config_get_profile_root_override () != NULL)
  68.      {
  69. -        dir = g_build_filename (mc_home, ".config", (char *) NULL);
  70. +        const char *profile_root;
  71. +
  72. +        profile_root = mc_config_get_profile_root ();
  73. +
  74. +        dir = g_build_filename (profile_root, ".config", (char *) NULL);
  75.          mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
  76.          g_free (dir);
  77.  
  78. -        dir = g_build_filename (mc_home, ".cache", (char *) NULL);
  79. +        dir = g_build_filename (profile_root, ".cache", (char *) NULL);
  80.          mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
  81.          g_free (dir);
  82.  
  83. -        dir = g_build_filename (mc_home, ".local", "share", (char *) NULL);
  84. +        dir = g_build_filename (profile_root, ".local", "share", (char *) NULL);
  85.          mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
  86.          g_free (dir);
  87.      }
  88. @@ -331,7 +366,7 @@ mc_config_init_config_paths (GError ** mcerror)
  89.      else
  90.      {
  91.          g_free (defined_userconf_dir);
  92. -        dir = g_build_filename (mc_config_get_home_dir (), MC_USERCONF_DIR, (char *) NULL);
  93. +        dir = g_build_filename (mc_config_get_profile_root (), MC_USERCONF_DIR, (char *) NULL);
  94.      }
  95.  
  96.      mc_data_str = mc_cache_str = mc_config_str = mc_config_init_one_config_path (dir, "", mcerror);
  97. @@ -393,15 +428,11 @@ mc_config_get_home_dir (void)
  98.  
  99.      if (homedir == NULL)
  100.      {
  101. -        homedir = g_getenv ("MC_HOME");
  102.          /* Prior to GLib 2.36, g_get_home_dir() ignores $HOME, which is why
  103.           * we read it ourselves. As that function's documentation explains,
  104.           * using $HOME is good for compatibility with other programs and
  105.           * for running from test frameworks. */
  106. -        if (homedir == NULL || *homedir == '\0')
  107. -            homedir = g_getenv ("HOME");
  108. -        else
  109. -            mc_home = homedir;
  110. +        homedir = g_getenv ("HOME");
  111.          if (homedir == NULL || *homedir == '\0')
  112.              homedir = g_get_home_dir ();
  113.      }
  114. --
  115. 2.5.0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top