Support maintaining original file UID/GID

This commit is contained in:
Kay Ohtie 2022-10-03 01:21:50 -05:00
parent 1bdf9684f3
commit 982ad84048

View file

@ -86,14 +86,20 @@ async def websocket_create(hass, connection, msg):
if not os.path.isdir(dirnm):
os.makedirs(dirnm, exist_ok=True)
try:
mode = os.stat(fullpath).st_mode
statres = os.stat(fullpath)
mode = statres.st_mode
uid = statres.st_uid
gid = statres.st_gid
except:
mode = 0o666
uid = 0
gid = 0
with AtomicWriter(fullpath, overwrite=True).open() as fdesc:
fdesc.write(content)
with open(fullpath, 'a') as fdesc:
try:
os.fchmod(fdesc.fileno(), mode)
os.fchown(fdesc.fileno(), uid, gid)
except:
pass
except: