From fbd74dedab359007993bfb8eb18d6791c3c8c081 Mon Sep 17 00:00:00 2001 From: htmltiger <1429451+htmltiger@users.noreply.github.com> Date: Fri, 4 Feb 2022 13:53:47 +0000 Subject: [PATCH] preserve permissions --- custom_components/config_editor/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/custom_components/config_editor/__init__.py b/custom_components/config_editor/__init__.py index 7d43341..062e6f1 100644 --- a/custom_components/config_editor/__init__.py +++ b/custom_components/config_editor/__init__.py @@ -77,9 +77,13 @@ async def websocket_create(hass, connection, msg): dirnm = os.path.dirname(fullpath) if not os.path.isdir(dirnm): os.makedirs(dirnm, exist_ok=True) + try: + mode = os.stat(fullpath).st_mode + except: + mode = 0o666 with AtomicWriter(fullpath, overwrite=True).open() as fdesc: try: - os.fchmod(fdesc.fileno(), 0o666) + os.fchmod(fdesc.fileno(), mode) except: pass fdesc.write(content)