From d6af07d79de7fde28ab275dc8d02756c91ca250a Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Mon, 16 Dec 2024 17:07:20 -0500 Subject: [PATCH] fix: use the same cache directory in providers Without this, the snap's `XDG_CACHE_DIR` environment variable will override the use of `/root/.cache` for caching in a provider. Work around this by just making them the same directory. --- charmcraft/services/provider.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/charmcraft/services/provider.py b/charmcraft/services/provider.py index 704a98f6f..27ec9d093 100644 --- a/charmcraft/services/provider.py +++ b/charmcraft/services/provider.py @@ -124,6 +124,13 @@ def instance( **kwargs, # type: ignore[arg-type] ) as instance: try: + # Use /root/.cache even if we're in the snap. + instance.execute_run( + ["rm", "-rf", "/root/snap/charmcraft/common/cache"] + ) + instance.execute_run( + ["ln", "-s", "/root/.cache", "/root/snap/charmcraft/common/cache"] + ) yield instance finally: if fcntl is not None and self._lock: