V6.1 runtime settings ->.env.production fix
Quality Gate / gate (push) Successful in 2m29s

This commit is contained in:
Jim Lancaster
2026-09-02 12:31:04 -05:00
parent 16391463d6
commit 15a4814e23
2 changed files with 32 additions and 1 deletions
+16 -1
View File
@@ -6,6 +6,9 @@ import os
import re
import tempfile
from dataclasses import dataclass
from errno import EBUSY
from errno import EPERM
from errno import EXDEV
from pathlib import Path
from typing import Literal
@@ -518,6 +521,7 @@ def _upsert_env_key(lines: list[str], key: str, value: str) -> None:
def _write_env_lines_atomic(*, path: Path, lines: list[str]) -> None:
temp_path: Path | None = None
try:
path.parent.mkdir(parents=True, exist_ok=True)
content = "\n".join(lines).rstrip("\n")
@@ -533,7 +537,15 @@ def _write_env_lines_atomic(*, path: Path, lines: list[str]) -> None:
) as handle:
temp_path = Path(handle.name)
handle.write(content)
temp_path.replace(path)
try:
temp_path.replace(path)
except OSError as exc:
# Single-file bind mounts can reject replace() (cross-device or busy mountpoint).
# Fallback to direct write so Runtime Settings can persist to mounted env files.
if exc.errno not in {EXDEV, EBUSY, EPERM}:
raise
with path.open("w", encoding="utf-8", newline="\n") as handle:
handle.write(content)
except OSError as exc:
raise AppError(
"Runtime settings file is not writable.",
@@ -541,6 +553,9 @@ def _write_env_lines_atomic(*, path: Path, lines: list[str]) -> None:
suggestion="Verify file path and write permissions, then retry.",
detail=f"Failed writing runtime env file {path}: {type(exc).__name__}: {exc}",
) from exc
finally:
if temp_path is not None:
temp_path.unlink(missing_ok=True)
def _escape_json_string(value: str) -> str: