Preserve file modes in operator updates
This commit is contained in:
@@ -17,6 +17,7 @@ import re
|
||||
import shlex
|
||||
import shutil
|
||||
import socketserver
|
||||
import stat
|
||||
import subprocess
|
||||
import tempfile
|
||||
import threading
|
||||
@@ -28,7 +29,7 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
VERSION = "2.3.2"
|
||||
VERSION = "2.3.3"
|
||||
STACK = Path(os.environ.get("ATHENA_OPERATOR_STACK", "/opt/mike-ai/stack")).resolve()
|
||||
REPOSITORY = Path(os.environ.get("ATHENA_OPERATOR_REPOSITORY", "/data/mike-ai-operator/repository")).resolve()
|
||||
STATE = Path(os.environ.get("ATHENA_OPERATOR_STATE", "/data/mike-ai-operator/state")).resolve()
|
||||
@@ -565,6 +566,7 @@ def prepare(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
def sync_file(relative: Path, content: str, backup_root: Path) -> None:
|
||||
for root in (REPOSITORY, STACK):
|
||||
target = source_file(root, relative)
|
||||
target_mode = stat.S_IMODE(target.stat().st_mode) if target.exists() else 0o644
|
||||
if target.exists():
|
||||
backup = backup_root / root.name / relative
|
||||
backup.parent.mkdir(parents=True, exist_ok=True)
|
||||
@@ -573,6 +575,7 @@ def sync_file(relative: Path, content: str, backup_root: Path) -> None:
|
||||
fd, temp_name = tempfile.mkstemp(prefix=f".{target.name}.", dir=target.parent)
|
||||
with os.fdopen(fd, "w", encoding="utf-8") as handle:
|
||||
handle.write(content)
|
||||
os.chmod(temp_name, target_mode)
|
||||
os.replace(temp_name, target)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user