Use XDG_CONFIG_HOME environment variable if it is present, otherwise fall back to ~/.config

This commit is contained in:
Miguel Jacq 2021-04-28 15:45:37 +10:00
parent 470fb2bda3
commit fe64d40e45
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6

View File

@ -133,13 +133,21 @@ class Common:
except:
# If for some reason we don't have the 'APPDATA' environment variable
# (like running tests in Linux while pretending to be in Windows)
onionshare_data_dir = os.path.expanduser("~/.config/onionshare")
try:
xdg_config_home = os.environ["XDG_CONFIG_HOME"]
onionshare_data_dir = f"{xdg_config_home}/onionshare"
except:
onionshare_data_dir = os.path.expanduser("~/.config/onionshare")
elif self.platform == "Darwin":
onionshare_data_dir = os.path.expanduser(
"~/Library/Application Support/OnionShare"
)
else:
onionshare_data_dir = os.path.expanduser("~/.config/onionshare")
try:
xdg_config_home = os.environ["XDG_CONFIG_HOME"]
onionshare_data_dir = f"{xdg_config_home}/onionshare"
except:
onionshare_data_dir = os.path.expanduser("~/.config/onionshare")
# Modify the data dir if running tests
if getattr(sys, "onionshare_test_mode", False):