From a357cdd7916e377674b5fa8f4b61e3409e102fd2 Mon Sep 17 00:00:00 2001 From: NeilSmithDLS Date: Mon, 27 Apr 2026 09:18:55 +0100 Subject: [PATCH 1/3] fix: create blueapi cache folder on login --- src/blueapi/service/authentication.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/blueapi/service/authentication.py b/src/blueapi/service/authentication.py index c0a32b26f4..488fdf26c1 100644 --- a/src/blueapi/service/authentication.py +++ b/src/blueapi/service/authentication.py @@ -52,6 +52,8 @@ def save_cache(self, cache: Cache) -> None: os.chmod(self._file_path, 0o600) def load_cache(self) -> Cache: + Path(self._file_path).mkdir(parents=True, exist_ok=True) + os.chmod(self._file_path, 0o600) with open(self._file_path, "rb") as cache_file: return TypeAdapter(Cache).validate_json( base64.b64decode(cache_file.read()).decode("utf-8") From 8ae30582a5f6b493af3d1a57f4a26b43bdd1ca4f Mon Sep 17 00:00:00 2001 From: NeilSmithDLS Date: Thu, 30 Apr 2026 09:36:38 +0100 Subject: [PATCH 2/3] creating folder correctly --- src/blueapi/service/authentication.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/blueapi/service/authentication.py b/src/blueapi/service/authentication.py index 488fdf26c1..d5e7747b6e 100644 --- a/src/blueapi/service/authentication.py +++ b/src/blueapi/service/authentication.py @@ -47,13 +47,13 @@ def _file_path(self) -> str: def save_cache(self, cache: Cache) -> None: self.delete_cache() + self._create_parent_folder_if_necessary() with open(self._file_path, "xb") as token_file: token_file.write(base64.b64encode(cache.model_dump_json().encode("utf-8"))) os.chmod(self._file_path, 0o600) def load_cache(self) -> Cache: - Path(self._file_path).mkdir(parents=True, exist_ok=True) - os.chmod(self._file_path, 0o600) + self._create_parent_folder_if_necessary() with open(self._file_path, "rb") as cache_file: return TypeAdapter(Cache).validate_json( base64.b64decode(cache_file.read()).decode("utf-8") @@ -73,6 +73,7 @@ def _default_token_cache_path() -> Path: def can_access_cache(self) -> bool: assert self._token_path try: + self._create_parent_folder_if_necessary() self._token_path.write_text("") except IsADirectoryError: print("Invalid path: a directory path was provided instead of a file path") @@ -82,6 +83,9 @@ def can_access_cache(self) -> bool: return False return True + def _create_parent_folder_if_necessary(self): + Path(self._token_path.parent).mkdir(mode=0o777, parents=True, exist_ok=True) + class SessionManager: def __init__(self, server_config: OIDCConfig, cache_manager: CacheManager) -> None: From 36ebbfc13f5d85195957ba5ef2352e9064237bc4 Mon Sep 17 00:00:00 2001 From: NeilSmithDLS Date: Thu, 30 Apr 2026 12:46:32 +0100 Subject: [PATCH 3/3] removing mode as using default --- src/blueapi/service/authentication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blueapi/service/authentication.py b/src/blueapi/service/authentication.py index d5e7747b6e..e21efeb2f2 100644 --- a/src/blueapi/service/authentication.py +++ b/src/blueapi/service/authentication.py @@ -84,7 +84,7 @@ def can_access_cache(self) -> bool: return True def _create_parent_folder_if_necessary(self): - Path(self._token_path.parent).mkdir(mode=0o777, parents=True, exist_ok=True) + Path(self._token_path.parent).mkdir(parents=True, exist_ok=True) class SessionManager: