mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-12 19:56:29 +00:00
Use atomic writes to make it more stable again full disk (#2267)
This commit is contained in:
parent
7aa039d162
commit
ecdf4e53b8
@ -1,5 +1,6 @@
|
||||
aiohttp==3.7.2
|
||||
async_timeout==3.0.1
|
||||
atomicwrites==1.4.0
|
||||
attrs==20.3.0
|
||||
brotlipy==0.7.0
|
||||
cchardet==2.1.7
|
||||
|
@ -4,6 +4,7 @@ import logging
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
from atomicwrites import atomic_write
|
||||
import voluptuous as vol
|
||||
from voluptuous.humanize import humanize_error
|
||||
|
||||
@ -17,7 +18,8 @@ _DEFAULT: Dict[str, Any] = {}
|
||||
def write_json_file(jsonfile: Path, data: Any) -> None:
|
||||
"""Write a JSON file."""
|
||||
try:
|
||||
jsonfile.write_text(json.dumps(data, indent=2))
|
||||
with atomic_write(jsonfile, overwrite=True) as fp:
|
||||
fp.write(json.dumps(data, indent=2))
|
||||
jsonfile.chmod(0o600)
|
||||
except (OSError, ValueError, TypeError) as err:
|
||||
_LOGGER.error("Can't write %s: %s", jsonfile, err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user