[RFC PATCH 04/13] b4: resolve platform-native data and cache directories

Adrian Neftali Sanchez <[email protected]>
Newsgroups org.kernel.linux.tools
Message-ID <[email protected]>
XDG_DATA_HOME and XDG_CACHE_HOME are honoured when set, covering custom
Linux/macOS setups.  Add a Windows branch that reads APPDATA (for data)
and LOCALAPPDATA (for cache) before falling back to the
pathlib.Path.home() equivalents, matching the Windows platform
convention.

Signed-off-by: Adrian Neftali Sanchez <[email protected]>
---
 src/b4/__init__.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index e878d34..bddf2db 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -3896,6 +3896,8 @@ def get_main_config() -> ConfigDictT:
 def get_data_dir(appname: str = 'b4') -> str:
     if 'XDG_DATA_HOME' in os.environ:
         datahome = os.environ['XDG_DATA_HOME']
+    elif sys.platform == 'win32':
+        datahome = os.environ.get('APPDATA', str(pathlib.Path.home() / 'AppData' / 'Roaming'))
     else:
         datahome = os.path.join(str(pathlib.Path.home()), '.local', 'share')
     datadir = os.path.join(datahome, appname)
@@ -3907,6 +3909,8 @@ def get_cache_dir(appname: str = 'b4') -> str:
     global _CACHE_CLEANED
     if 'XDG_CACHE_HOME' in os.environ:
         cachehome = os.environ['XDG_CACHE_HOME']
+    elif sys.platform == 'win32':
+        cachehome = os.environ.get('LOCALAPPDATA', str(pathlib.Path.home() / 'AppData' / 'Local'))
     else:
         cachehome = os.path.join(str(pathlib.Path.home()), '.cache')
     cachedir = os.path.join(cachehome, appname)
-- 
2.45.0.windows.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.