From d0607e188b417139489e22250db66119e8871026 Mon Sep 17 00:00:00 2001 From: Dung Nguyen Date: Mon, 1 Sep 2025 18:12:18 +0700 Subject: [PATCH] Fix cachedir on Windows (#3280) * Fix cachedir on Windows * Update pwndbg/lib/tempfile.py Co-authored-by: patryk4815 --------- Co-authored-by: patryk4815 --- pwndbg/lib/tempfile.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pwndbg/lib/tempfile.py b/pwndbg/lib/tempfile.py index 16322d21d..7e621e3bd 100644 --- a/pwndbg/lib/tempfile.py +++ b/pwndbg/lib/tempfile.py @@ -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)