Skip to content

Commit

Permalink
Respect XDG Base Directory spec for pwntools cache (#1420)
Browse files Browse the repository at this point in the history
Fix #1370
  • Loading branch information
alichtman authored Feb 1, 2020
1 parent 42abafd commit 8f941b8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pwnlib/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,12 +1225,13 @@ def cache_dir(self):
>>> cache_dir == context.cache_dir
True
"""
home = os.path.expanduser('~')
xdg_cache_home = os.environ.get('XDG_CACHE_HOME') or \
os.path.join(os.path.expanduser('~'), '.cache')

if not os.access(home, os.W_OK):
if not os.access(xdg_cache_home, os.W_OK):
return None

cache = os.path.join(home, '.pwntools-cache-%d.%d' % sys.version_info[:2])
cache = os.path.join(xdg_cache_home, '.pwntools-cache-%d.%d' % sys.version_info[:2])

if not os.path.exists(cache):
try:
Expand Down

0 comments on commit 8f941b8

Please sign in to comment.