Merge pull request #16 from junkfix/junkfix-patch-1

fix blocking error
This commit is contained in:
junkfix 2024-06-07 20:59:52 +01:00 committed by GitHub
commit b7ad97aba7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -66,8 +66,10 @@ async def websocket_create(hass, connection, msg):
content = '' content = ''
res = 'Loaded' res = 'Loaded'
try: try:
with open(fullpath, encoding="utf-8") as fdesc: def read():
content = fdesc.read() with open(fullpath, encoding="utf-8") as fdesc:
return fdesc.read()
content = await hass.async_add_executor_job(read)
except: except:
res = 'Reading Failed' res = 'Reading Failed'
_LOGGER.exception("Reading failed: %s", fullpath) _LOGGER.exception("Reading failed: %s", fullpath)
@ -96,12 +98,16 @@ async def websocket_create(hass, connection, msg):
gid = 0 gid = 0
with AtomicWriter(fullpath, overwrite=True).open() as fdesc: with AtomicWriter(fullpath, overwrite=True).open() as fdesc:
fdesc.write(content) fdesc.write(content)
with open(fullpath, 'a') as fdesc:
try: def permi():
os.fchmod(fdesc.fileno(), mode) with open(fullpath, 'a') as fdesc:
os.fchown(fdesc.fileno(), uid, gid) try:
except: os.fchmod(fdesc.fileno(), mode)
pass os.fchown(fdesc.fileno(), uid, gid)
except:
pass
await hass.async_add_executor_job(permi)
except: except:
res = "Saving Failed" res = "Saving Failed"
_LOGGER.exception(res+": %s", fullpath) _LOGGER.exception(res+": %s", fullpath)