consolidate version check, flush instead of wait

This commit is contained in:
phact 2025-12-01 15:42:30 -05:00
parent 559f1e319b
commit 6cd1dc2664
2 changed files with 15 additions and 11 deletions

View file

@ -1,8 +1,5 @@
"""OpenRAG Terminal User Interface package."""
from importlib.metadata import version
from .utils.version_check import get_current_version
try:
__version__ = version("openrag")
except Exception:
__version__ = "unknown"
__version__ = get_current_version()

View file

@ -590,14 +590,21 @@ class EnvManager:
break
new_lines.insert(insert_pos, f"OPENRAG_VERSION={self._quote_env_value(current_version)}")
self.env_file.write_text("\n".join(new_lines) + "\n")
with open(self.env_file, 'w') as f:
f.write("\n".join(new_lines) + "\n")
f.flush()
os.fsync(f.fileno())
else:
# Create new .env file with just OPENRAG_VERSION
self.env_file.write_text(
f"# OpenRAG Environment Configuration\n"
f"# Generated by OpenRAG TUI\n\n"
f"OPENRAG_VERSION={self._quote_env_value(current_version)}\n"
)
with open(self.env_file, 'w') as f:
content = (
f"# OpenRAG Environment Configuration\n"
f"# Generated by OpenRAG TUI\n\n"
f"OPENRAG_VERSION={self._quote_env_value(current_version)}\n"
)
f.write(content)
f.flush()
os.fsync(f.fileno())
except Exception as e:
logger.debug(f"Error ensuring OPENRAG_VERSION: {e}")