Skip to content

Commit

Permalink
Use XDG_*_HOME vars
Browse files Browse the repository at this point in the history
  • Loading branch information
tilosp committed Sep 3, 2019
1 parent d634301 commit 208d0a2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions torbrowser_launcher/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ def discover_arch_lang(self):
if self.language not in available_languages:
self.language = 'en-US'

# get value of environment variable, if it is not set return the default value
@staticmethod
def get_env(var_name, default_value):
value = os.getenv(var_name)
if not value:
value = default_value
return value

# build all relevant paths
def build_paths(self, tbb_version=None):
homedir = os.getenv('HOME')
Expand All @@ -101,9 +109,9 @@ def build_paths(self, tbb_version=None):
if not os.access(homedir, os.W_OK):
self.set_gui('error', _("{0} is not writable").format(homedir), [], False)

tbb_config = '{0}/.config/torbrowser'.format(homedir)
tbb_cache = '{0}/.cache/torbrowser'.format(homedir)
tbb_local = '{0}/.local/share/torbrowser'.format(homedir)
tbb_config = '{0}/torbrowser'.format(self.get_env('XDG_CONFIG_HOME', '{0}/.config'.format(homedir)))
tbb_cache = '{0}/torbrowser'.format(self.get_env('XDG_CACHE_HOME', '{0}/.cache'.format(homedir)))
tbb_local = '{0}/torbrowser'.format(self.get_env('XDG_DATA_HOME', '{0}/.local/share'.format(homedir)))
old_tbb_data = '{0}/.torbrowser'.format(homedir)

if tbb_version:
Expand Down

2 comments on commit 208d0a2

@blackpidgeon
Copy link

@blackpidgeon blackpidgeon commented on 208d0a2 Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables are not set by default on Debian 10 Buster!
@tilosp

@tilosp
Copy link
Contributor Author

@tilosp tilosp commented on 208d0a2 Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blackpidgeon
yes they are almost never set by any distro by default. This is why there is a falback to ~/.config, ~/.cache and ~/.local/share.
I don't see what problem is caused by running without them set.
See the XDG Base Directory Specification for more info.

Please sign in to comment.