summaryrefslogtreecommitdiff
path: root/py_modules
diff options
context:
space:
mode:
authorxXJSONDeruloXx <danielhimebauch@gmail.com>2025-07-17 21:00:44 -0400
committerxXJSONDeruloXx <danielhimebauch@gmail.com>2025-07-17 21:00:44 -0400
commit620c04f75ad0f6025cc26f73dd07c466d6e1c62e (patch)
treea96afdb471cd6b475d766463987f03807c6f0a89 /py_modules
parentad0ba0fc61f83e2aaf22192e7d0ad05dde9ffd62 (diff)
downloaddecky-lsfg-vk-620c04f75ad0f6025cc26f73dd07c466d6e1c62e.tar.gz
decky-lsfg-vk-620c04f75ad0f6025cc26f73dd07c466d6e1c62e.zip
fix config writes
Diffstat (limited to 'py_modules')
-rw-r--r--py_modules/lsfg_vk/base_service.py37
-rw-r--r--py_modules/lsfg_vk/configuration.py10
-rw-r--r--py_modules/lsfg_vk/installation.py4
3 files changed, 18 insertions, 33 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
diff --git a/py_modules/lsfg_vk/configuration.py b/py_modules/lsfg_vk/configuration.py
index c15fc37..a4fcae5 100644
--- a/py_modules/lsfg_vk/configuration.py
+++ b/py_modules/lsfg_vk/configuration.py
@@ -89,11 +89,11 @@ class ConfigurationService(BaseService):
# Generate TOML content using centralized manager
toml_content = ConfigurationManager.generate_toml_content(config)
- # Ensure config directory exists
+ # Ensure config directory exists
self.config_dir.mkdir(parents=True, exist_ok=True)
- # Write the updated config atomically
- self._atomic_write(self.config_file_path, toml_content, 0o644)
+ # Write the updated config directly to preserve inode for file watchers
+ self._write_file(self.config_file_path, toml_content, 0o644)
self.log.info(f"Updated lsfg TOML configuration: enable={enable}, "
f"dll='{dll}', multiplier={multiplier}, flow_scale={flow_scale}, "
@@ -154,8 +154,8 @@ class ConfigurationService(BaseService):
# Ensure config directory exists
self.config_dir.mkdir(parents=True, exist_ok=True)
- # Write the updated config atomically
- self._atomic_write(self.config_file_path, toml_content, 0o644)
+ # Write the updated config directly to preserve inode for file watchers
+ self._write_file(self.config_file_path, toml_content, 0o644)
self.log.info(f"Updated DLL path in lsfg configuration: '{dll_path}'")
diff --git a/py_modules/lsfg_vk/installation.py b/py_modules/lsfg_vk/installation.py
index 27be850..fc9ac97 100644
--- a/py_modules/lsfg_vk/installation.py
+++ b/py_modules/lsfg_vk/installation.py
@@ -114,8 +114,8 @@ class InstallationService(BaseService):
# Generate TOML content using centralized manager
toml_content = ConfigurationManager.generate_toml_content(config)
- # Use atomic write to prevent corruption
- self._atomic_write(self.config_file_path, toml_content, 0o644)
+ # Write initial config file
+ self._write_file(self.config_file_path, toml_content, 0o644)
self.log.info(f"Created config file at {self.config_file_path}")
# Log detected DLL path if found