config: Ignore non-absolute XDG_CACHE_HOME.
Per the spec.
This commit is contained in:
parent
c7fbf5b5d5
commit
24813a9b81
2 changed files with 12 additions and 0 deletions
|
@ -81,6 +81,11 @@ class Config:
|
||||||
try:
|
try:
|
||||||
cache_root = Path(os.environ['XDG_CACHE_HOME'])
|
cache_root = Path(os.environ['XDG_CACHE_HOME'])
|
||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
|
ok = False
|
||||||
|
else:
|
||||||
|
# Per the spec, non-absolute paths should be ignored.
|
||||||
|
ok = cache_root.is_absolute()
|
||||||
|
if not ok:
|
||||||
cache_root = Path.home() / '.cache'
|
cache_root = Path.home() / '.cache'
|
||||||
return (
|
return (
|
||||||
self._dir_or_none(cache_root)
|
self._dir_or_none(cache_root)
|
||||||
|
|
|
@ -283,6 +283,13 @@ def test_cache_path_parent_conflict(tmp_path):
|
||||||
config = config_mod.Config()
|
config = config_mod.Config()
|
||||||
assert config.cache_dir_path('TESTcache') is None
|
assert config.cache_dir_path('TESTcache') is None
|
||||||
|
|
||||||
|
def test_relative_xdg_cache_home_ignored(tmp_path):
|
||||||
|
with update_environ(HOME=tmp_path,
|
||||||
|
XDG_CACHE_HOME='nonexistent/test/cache/directory/tree'):
|
||||||
|
config = config_mod.Config()
|
||||||
|
cache_dir_path = config.cache_dir_path('TESTcache')
|
||||||
|
assert cache_dir_path == tmp_path / '.cache/TESTcache'
|
||||||
|
|
||||||
def test_payment_threshold():
|
def test_payment_threshold():
|
||||||
threshold = config_mod.Config().payment_threshold()
|
threshold = config_mod.Config().payment_threshold()
|
||||||
assert threshold == 0
|
assert threshold == 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue