From 2800de0b4ad2b41bfaa95eec941ee719baa25893 Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Sat, 9 May 2026 12:04:46 -0400 Subject: [PATCH] fix: preserve .hb.yaml file permissions on backup and atomic write --- hbd/server/configio.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hbd/server/configio.py b/hbd/server/configio.py index 0d7fa7f..1e8495e 100644 --- a/hbd/server/configio.py +++ b/hbd/server/configio.py @@ -48,9 +48,12 @@ def write_config(path: str, data) -> None: while os.path.exists(backup_path): n += 1 backup_path = f"{path}.bak.{ts}-{n}" + orig_mode = None if os.path.exists(path): + orig_mode = os.stat(path).st_mode with open(path, "rb") as src, open(backup_path, "wb") as dst: dst.write(src.read()) + os.chmod(backup_path, orig_mode) backups = sorted(glob.glob(f"{path}.bak.*"), reverse=True) for old in backups[10:]: os.unlink(old) @@ -58,6 +61,8 @@ def write_config(path: str, data) -> None: try: with open(tmp, "w", encoding="utf-8") as f: _make_yaml().dump(data, f) + if orig_mode is not None: + os.chmod(tmp, orig_mode) os.replace(tmp, path) except Exception: try: