diff --git a/backend/config/config_manager.py b/backend/config/config_manager.py index 1c17ad854..283ffbc5d 100644 --- a/backend/config/config_manager.py +++ b/backend/config/config_manager.py @@ -4,6 +4,7 @@ import glob import json import os import sys +from pathlib import Path from typing import Final, NotRequired, TypedDict import pydash @@ -189,16 +190,14 @@ class ConfigManager: self._validate_config() def _create_missing_config_file(self) -> None: - log.warning(f"Config file not found, creating an empty config at {hl(self.config_file, BLUE)}") + log.warning( + f"Config file not found, creating an empty config at {hl(self.config_file, BLUE)}" + ) try: os.makedirs(os.path.dirname(self.config_file), exist_ok=True) - with open(self.config_file, "x"): - pass + Path(self.config_file).touch(exist_ok=True) - self._config_file_mounted = True - self._config_file_writable = os.access(self.config_file, os.W_OK) - except FileExistsError: self._config_file_mounted = True self._config_file_writable = os.access(self.config_file, os.W_OK) except PermissionError: diff --git a/backend/tests/config/test_config_loader.py b/backend/tests/config/test_config_loader.py index faa9c8d10..72b57f940 100644 --- a/backend/tests/config/test_config_loader.py +++ b/backend/tests/config/test_config_loader.py @@ -120,6 +120,7 @@ def test_missing_config_file_is_created(tmp_path): loader = ConfigManager(str(config_file)) + assert config_file.parent.exists() assert config_file.exists() assert config_file.read_text() == "" assert loader.config.CONFIG_FILE_MOUNTED