diff options
| author | xXJSONDeruloXx <danielhimebauch@gmail.com> | 2025-07-17 21:00:44 -0400 |
|---|---|---|
| committer | xXJSONDeruloXx <danielhimebauch@gmail.com> | 2025-07-17 21:00:44 -0400 |
| commit | 620c04f75ad0f6025cc26f73dd07c466d6e1c62e (patch) | |
| tree | a96afdb471cd6b475d766463987f03807c6f0a89 /py_modules/lsfg_vk/base_service.py | |
| parent | ad0ba0fc61f83e2aaf22192e7d0ad05dde9ffd62 (diff) | |
| download | decky-lsfg-vk-620c04f75ad0f6025cc26f73dd07c466d6e1c62e.tar.gz decky-lsfg-vk-620c04f75ad0f6025cc26f73dd07c466d6e1c62e.zip | |
fix config writes
Diffstat (limited to 'py_modules/lsfg_vk/base_service.py')
| -rw-r--r-- | py_modules/lsfg_vk/base_service.py | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/py_modules/lsfg_vk/base_service.py b/py_modules/lsfg_vk/base_service.py index 92ac152..a796480 100644 --- a/py_modules/lsfg_vk/base_service.py +++ b/py_modules/lsfg_vk/base_service.py @@ -4,7 +4,6 @@ Base service class with common functionality. import os import shutil -import tempfile from pathlib import Path from typing import Any, Optional @@ -65,8 +64,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 @@ -76,31 +75,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 |
