Ticket #3641: mc-3641-cleanup-paths_c.patch

File mc-3641-cleanup-paths_c.patch, 3.2 KB (added by mooffie, 8 years ago)
  • lib/mcconfig/paths.c

    From 6497f1ef44427b31176495178de195be448ed7d8 Mon Sep 17 00:00:00 2001
    From: Mooffie <mooffie@gmail.com>
    Date: Thu, 8 Sep 2016 00:51:20 +0300
    Subject: [PATCH] lib/mcconfig/paths.c: cleanup.
    
    We can conclude, by reading their GLib source[1], by their documentation,
    and by looking at how popular programs use them[2], that the functions
    g_get_user_{config,cache,data}_dir() don't return a NULL or empty string.
    So the handling of this case can go.
    
    [1] https://git.gnome.org/browse/glib/tree/glib/gutils.c
    [2] E.g., google "g_get_user_data_dir".
    ---
     lib/mcconfig/paths.c | 41 ++++++++++-------------------------------
     1 file changed, 10 insertions(+), 31 deletions(-)
    
    diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c
    index 1129e24..4e2f2c5 100644
    a b mc_config_init_config_paths (GError ** mcerror) 
    289289    char *dir; 
    290290#if MC_HOMEDIR_XDG == 0 
    291291    char *defined_userconf_dir; 
    292 #else 
    293     const char *cdir; 
    294292#endif 
    295293 
    296294    mc_return_if_error (mcerror); 
    mc_config_init_config_paths (GError ** mcerror) 
    318316    } 
    319317    else 
    320318    { 
    321         cdir = g_get_user_config_dir (); 
    322         if (cdir != NULL && *cdir != '\0') 
    323             mc_config_str = mc_config_init_one_config_path (cdir, MC_USERCONF_DIR, mcerror); 
    324         else 
    325         { 
    326             dir = g_build_filename (homedir, ".config", (char *) NULL); 
    327             mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); 
    328             g_free (dir); 
    329         } 
    330  
    331         cdir = g_get_user_cache_dir (); 
    332         if (cdir != NULL && *cdir != '\0') 
    333             mc_cache_str = mc_config_init_one_config_path (cdir, MC_USERCONF_DIR, mcerror); 
    334         else 
    335         { 
    336             dir = g_build_filename (homedir, ".cache", (char *) NULL); 
    337             mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); 
    338             g_free (dir); 
    339         } 
    340  
    341         cdir = g_get_user_data_dir (); 
    342         if (cdir != NULL && *cdir != '\0') 
    343             mc_data_str = mc_config_init_one_config_path (cdir, MC_USERCONF_DIR, mcerror); 
    344         else 
    345         { 
    346             dir = g_build_filename (homedir, ".local", "share", (char *) NULL); 
    347             mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror); 
    348             g_free (dir); 
    349         } 
     319        mc_config_str = 
     320            mc_config_init_one_config_path (g_get_user_config_dir (), MC_USERCONF_DIR, mcerror); 
     321        mc_cache_str = 
     322            mc_config_init_one_config_path (g_get_user_cache_dir (), MC_USERCONF_DIR, mcerror); 
     323        mc_data_str = 
     324            mc_config_init_one_config_path (g_get_user_data_dir (), MC_USERCONF_DIR, mcerror); 
    350325    } 
    351326 
    352327    mc_config_fix_migrated_rules (); 
    mc_config_get_home_dir (void) 
    418393    if (homedir == NULL) 
    419394    { 
    420395        homedir = g_getenv ("MC_HOME"); 
     396        /* Prior to GLib 2.36, g_get_home_dir() ignores $HOME, which is why 
     397         * we read it ourselves. As that function's documentation explains, 
     398         * using $HOME is good for compatibility with other programs and 
     399         * for running from test frameworks. */ 
    421400        if (homedir == NULL || *homedir == '\0') 
    422401            homedir = g_getenv ("HOME"); 
    423402        else