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); |
107 | 107 | |
108 | 108 | const char *mc_config_get_path (void); |
109 | 109 | |
| 110 | const char *mc_config_get_profile_root (void); |
| 111 | |
110 | 112 | const char *mc_config_get_home_dir (void); |
111 | 113 | |
112 | 114 | char *mc_config_get_full_path (const char *config_name); |
diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c
index 7c34622..d2f478a 100644
a
|
b
|
static char *mc_config_str = NULL; |
51 | 51 | static char *mc_cache_str = NULL; |
52 | 52 | static char *mc_data_str = NULL; |
53 | 53 | |
54 | | /* value of $MC_HOME */ |
55 | | static const char *mc_home = NULL; |
56 | | |
57 | 54 | static gboolean config_dir_present = FALSE; |
58 | 55 | |
59 | 56 | static const struct |
… |
… |
mc_config_deprecated_dir_present (void) |
282 | 279 | /*** public functions ****************************************************************************/ |
283 | 280 | /* --------------------------------------------------------------------------------------------- */ |
284 | 281 | |
| 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 | */ |
| 289 | const char * |
| 290 | mc_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 | |
285 | 306 | void |
286 | 307 | mc_config_init_config_paths (GError ** mcerror) |
287 | 308 | { |
… |
… |
mc_config_init_config_paths (GError ** mcerror) |
295 | 316 | if (xdg_vars_initialized) |
296 | 317 | return; |
297 | 318 | |
298 | | /* init mc_home if not yet */ |
299 | | (void) mc_config_get_home_dir (); |
300 | | |
301 | 319 | #if MC_HOMEDIR_XDG |
302 | | if (mc_home != NULL) |
| 320 | if (strcmp (mc_config_get_profile_root (), mc_config_get_home_dir ()) != 0) |
303 | 321 | { |
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); |
305 | 334 | mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); |
306 | 335 | g_free (dir); |
307 | 336 | |
308 | | dir = g_build_filename (mc_home, ".cache", (char *) NULL); |
| 337 | dir = g_build_filename (profile_root, ".cache", (char *) NULL); |
309 | 338 | mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); |
310 | 339 | g_free (dir); |
311 | 340 | |
312 | | dir = g_build_filename (mc_home, ".local", "share", (char *) NULL); |
| 341 | dir = g_build_filename (profile_root, ".local", "share", (char *) NULL); |
313 | 342 | mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); |
314 | 343 | g_free (dir); |
315 | 344 | } |
… |
… |
mc_config_init_config_paths (GError ** mcerror) |
331 | 360 | else |
332 | 361 | { |
333 | 362 | 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); |
335 | 364 | } |
336 | 365 | |
337 | 366 | mc_data_str = mc_cache_str = mc_config_str = mc_config_init_one_config_path (dir, "", mcerror); |
… |
… |
mc_config_get_home_dir (void) |
393 | 422 | |
394 | 423 | if (homedir == NULL) |
395 | 424 | { |
396 | | homedir = g_getenv ("MC_HOME"); |
397 | 425 | /* Prior to GLib 2.36, g_get_home_dir() ignores $HOME, which is why |
398 | 426 | * we read it ourselves. As that function's documentation explains, |
399 | 427 | * using $HOME is good for compatibility with other programs and |
400 | 428 | * 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"); |
405 | 430 | if (homedir == NULL || *homedir == '\0') |
406 | 431 | homedir = g_get_home_dir (); |
407 | 432 | } |
diff --git a/src/textconf.c b/src/textconf.c
index b743715..736f7cb 100644
a
|
b
|
show_version (void) |
195 | 195 | void |
196 | 196 | show_datadirs_extended (void) |
197 | 197 | { |
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 ()); |
199 | 200 | (void) puts (""); |
200 | 201 | |
201 | 202 | PRINTF_GROUP (_("System data")); |