Fix cachedir on Windows (#3280)

* Fix cachedir on Windows

* Update pwndbg/lib/tempfile.py

Co-authored-by: patryk4815 <bux.patryk@gmail.com>

---------

Co-authored-by: patryk4815 <bux.patryk@gmail.com>
pull/3286/head
Dung Nguyen 3 months ago committed by GitHub
parent 2b928632dd
commit d0607e188b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -5,6 +5,7 @@ Common helper and cache for pwndbg tempdir
from __future__ import annotations
import os
import sys
import tempfile
import pwndbg.lib.cache
@ -22,12 +23,15 @@ def tempdir() -> str:
def cachedir(namespace: str | None = None) -> str:
"""
Returns and potentially creates a persistent safe cachedir location
based on XDG_CACHE_HOME or ~/.cache
based on XDG_CACHE_HOME or ~/.cache or LOCALAPPDATA (Windows)
Optionally creates a sub namespace inside the pwndbg cache folder.
"""
cachehome = os.getenv("XDG_CACHE_HOME") or os.path.join(os.getenv("HOME", ""), ".cache")
cachedir = os.path.join(cachehome, "pwndbg")
if sys.platform == "win32":
cachehome = os.getenv("LOCALAPPDATA")
else:
cachehome = os.getenv("XDG_CACHE_HOME") or os.path.join(os.getenv("HOME", ""), ".cache")
cachedir = os.path.join(cachehome or tempfile.gettempdir(), "pwndbg")
if namespace:
cachedir = os.path.join(cachedir, namespace)
os.makedirs(cachedir, exist_ok=True)

Loading…
Cancel
Save