summaryrefslogtreecommitdiff
path: root/py_modules/lsfg_vk/base_service.py
diff options
context:
space:
mode:
Diffstat (limited to 'py_modules/lsfg_vk/base_service.py')
-rw-r--r--py_modules/lsfg_vk/base_service.py45
1 files changed, 17 insertions, 28 deletions
diff --git a/py_modules/lsfg_vk/base_service.py b/py_modules/lsfg_vk/base_service.py
index b547759..b595b07 100644
--- a/py_modules/lsfg_vk/base_service.py
+++ b/py_modules/lsfg_vk/base_service.py
@@ -4,11 +4,10 @@ Base service class with common functionality.
import os
import shutil
-import tempfile
from pathlib import Path
from typing import Any, Optional
-from .constants import LOCAL_LIB, LOCAL_SHARE_BASE, VULKAN_LAYER_DIR, SCRIPT_NAME
+from .constants import LOCAL_LIB, LOCAL_SHARE_BASE, VULKAN_LAYER_DIR, SCRIPT_NAME, CONFIG_DIR, CONFIG_FILENAME
class BaseService:
@@ -31,12 +30,16 @@ class BaseService:
self.local_lib_dir = self.user_home / LOCAL_LIB
self.local_share_dir = self.user_home / VULKAN_LAYER_DIR
self.lsfg_script_path = self.user_home / SCRIPT_NAME
+ self.lsfg_launch_script_path = self.user_home / SCRIPT_NAME # ~/lsfg launch script
+ self.config_dir = self.user_home / CONFIG_DIR
+ self.config_file_path = self.config_dir / CONFIG_FILENAME
def _ensure_directories(self) -> None:
"""Create necessary directories if they don't exist"""
self.local_lib_dir.mkdir(parents=True, exist_ok=True)
self.local_share_dir.mkdir(parents=True, exist_ok=True)
- self.log.info(f"Ensured directories exist: {self.local_lib_dir}, {self.local_share_dir}")
+ self.config_dir.mkdir(parents=True, exist_ok=True)
+ self.log.info(f"Ensured directories exist: {self.local_lib_dir}, {self.local_share_dir}, {self.config_dir}")
def _remove_if_exists(self, path: Path) -> bool:
"""Remove a file if it exists
@@ -62,8 +65,8 @@ class BaseService:
self.log.info(f"File not found: {path}")
return False
- def _atomic_write(self, path: Path, content: str, mode: int = 0o644) -> None:
- """Write content to a file atomically
+ def _write_file(self, path: Path, content: str, mode: int = 0o644) -> None:
+ """Write content to a file
Args:
path: Target file path
@@ -73,31 +76,17 @@ class BaseService:
Raises:
OSError: If write fails
"""
- # Create temporary file in the same directory to ensure atomic move
- temp_path = None
try:
- with tempfile.NamedTemporaryFile(
- mode='w',
- dir=path.parent,
- delete=False,
- prefix=f'.{path.name}.',
- suffix='.tmp'
- ) as temp_file:
- temp_file.write(content)
- temp_path = Path(temp_file.name)
+ # Write directly to the file
+ with open(path, 'w', encoding='utf-8') as f:
+ f.write(content)
+ f.flush() # Ensure data is written to disk
+ os.fsync(f.fileno()) # Force filesystem sync
- # Set permissions before moving
- temp_path.chmod(mode)
-
- # Atomic move
- temp_path.replace(path)
- self.log.info(f"Atomically wrote to {path}")
+ # Set permissions
+ path.chmod(mode)
+ self.log.info(f"Wrote to {path}")
except Exception:
- # Clean up temp file if something went wrong
- if temp_path and temp_path.exists():
- try:
- temp_path.unlink()
- except OSError:
- pass # Best effort cleanup
+ self.log.error(f"Failed to write to {path}")
raise