reopen    688932
retitle   688932 g_get_user_{cache,config,data}_dir () fail to meet XDG Base 
Directory Specification 
severity  688932 minor
thanks

        [Re-opening, as it's essentially the same issue, and it's /not/
        resolved.  I also hope to forward this one to the upstream
        tracker, possibly with a patch, sometime next week.]

        As per XDG Base Directory Specification 0.8 (quoted below), the
        default values for XDG_CACHE_HOME, XDG_CONFIG_HOME, and
        XDG_DATA_HOME, are both defined relative to the value of the
        HOME environment variable.  Contrary to that, the respective
        g_get_user_{cache,config,data}_dir () functions return values
        relative to the user's /initial/ home directory (as per
        getpwuid ()->pw_dir) by default instead.

        Consider, e. g. (the source is MIME'd):

$ LC_ALL=C make LDFLAGS=-lglib-2.0 ugpzy4dbahtheg6tnc1m39anxd 
cc  -lglib-2.0  ugpzy4dbahtheg6tnc1m39anxd.c   -o ugpzy4dbahtheg6tnc1m39anxd
$ ./ugpzy4dbahtheg6tnc1m39anxd 
XDG_CACHE_HOME  => /home/private/users/jrh/.cache
XDG_CONFIG_HOME => /home/private/users/jrh/.config
XDG_DATA_HOME   => /home/private/users/jrh/.local/share
$ HOME=$(mktemp -dt -- foo.XXXXXXXX) ./ugpzy4dbahtheg6tnc1m39anxd 
XDG_CACHE_HOME  => /home/private/users/jrh/.cache
XDG_CONFIG_HOME => /home/private/users/jrh/.config
XDG_DATA_HOME   => /home/private/users/jrh/.local/share
$ (HOME=$(mktemp -dt -- foo.XXXXXXXX) \
       && XDG_CACHE_HOME=${HOME}/.cache \
              XDG_CONFIG_HOME=${HOME}/.config \
              XDG_DATA_HOME=${HOME}/.local/share \
              ./ugpzy4dbahtheg6tnc1m39anxd) 
XDG_CACHE_HOME  => /tmp/foo.nmGK6HNL/.cache
XDG_CONFIG_HOME => /tmp/foo.nmGK6HNL/.config
XDG_DATA_HOME   => /tmp/foo.nmGK6HNL/.local/share
$ 

        The end result is that the calling applications become
        non-compliant to the specification.

        Could this please be fixed?

        TIA.

PS.  As it seems, the easiest way to fix this issue is to change
        g_get_home_dir () to prefer HOME over the value returned by
        getpwuid () (either in the “sane” cases, or always), as was
        suggested before.  This would also fix the applications which
        choose not to use g_get_user_*_dir (), and call the plain old
        g_get_home_dir () instead.

--cut: http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html --
    $XDG_DATA_HOME defines the base directory relative to which user
    specific data files should be stored.  If $XDG_DATA_HOME is either
    not set or empty, a default equal to $HOME/.local/share should be
    used.

    $XDG_CONFIG_HOME defines the base directory relative to which user
    specific configuration files should be stored.  If $XDG_CONFIG_HOME is
    either not set or empty, a default equal to $HOME/.config should be
    used.

…

    $XDG_CACHE_HOME defines the base directory relative to which user
    specific non-essential data files should be stored.  If
    $XDG_CACHE_HOME is either not set or empty, a default equal to
    $HOME/.cache should be used.
--cut: http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html --

-- 
FSF associate member #7257
/*** ugpzy4dbahtheg6tnc1m39anxd.c  -*- C -*- */

#include <stdio.h>

const char *g_get_user_cache_dir  (void);
const char *g_get_user_config_dir (void);
const char *g_get_user_data_dir   (void);

int
main ()
{
  printf (("XDG_CACHE_HOME  => %s\n"
           "XDG_CONFIG_HOME => %s\n"
           "XDG_DATA_HOME   => %s\n"),
          g_get_user_cache_dir  (),
          g_get_user_config_dir (),
          g_get_user_data_dir   ());
  /* . */
  return 0;
}

/*** ugpzy4dbahtheg6tnc1m39anxd.c ends here */

Reply via email to