From c97fb7d3d365e86864e1659c040f0b3a5c8a2cbd Mon Sep 17 00:00:00 2001 From: 2xB <2xB@users.noreply.github.com> Date: Fri, 1 Mar 2019 22:00:44 +0100 Subject: [PATCH] XDG_DATA_DIRS useage corrected, fixes wrong site_data_dir under Kubuntu The freedesktop specification states that $XDG_DATA_DIRS is a preference ordered list of where data should be searched (as opposed to where applications should store data). Therefore, for multipath=False, which is used by applications to determine a path to store data, this can lead to unintended paths, as can be seen under issue #121. This commit changes the default directory in this case to the distribution independent '/usr/local/share'. --- appdirs.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/appdirs.py b/appdirs.py index 975e9bf..6b7987d 100644 --- a/appdirs.py +++ b/appdirs.py @@ -142,20 +142,20 @@ def site_data_dir(appname=None, appauthor=None, version=None, multipath=False): if appname: path = os.path.join(path, appname) else: - # XDG default for $XDG_DATA_DIRS - # only first, if multipath is False - path = os.getenv('XDG_DATA_DIRS', - os.pathsep.join(['/usr/local/share', '/usr/share'])) - pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)] + # XDG default: $XDG_DATA_DIRS for searching through multiple directories, + # '/usr/local/share' for single application directory + # (for distribution independent files, also '/usr/share' could be used) + if multipath: + path = os.getenv('XDG_DATA_DIRS', + os.pathsep.join(['/usr/local/share', '/usr/share'])) + pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)] + else: + pathlist = ['/usr/local/share'] if appname: if version: appname = os.path.join(appname, version) pathlist = [os.sep.join([x, appname]) for x in pathlist] - - if multipath: - path = os.pathsep.join(pathlist) - else: - path = pathlist[0] + path = os.pathsep.join(pathlist) return path if appname and version: