mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-27 11:06:32 +00:00
Use multipart for snapshot uploads (#2076)
* Use multipart for snapshot uploads * Wrap I/O and run in executor * revert 7f26b43 * remove cleanup
This commit is contained in:
parent
f1121fe66f
commit
a9abd933b5
@ -182,11 +182,15 @@ class APISnapshots(CoreSysAttributes):
|
|||||||
"""Upload a snapshot file."""
|
"""Upload a snapshot file."""
|
||||||
with TemporaryDirectory(dir=str(self.sys_config.path_tmp)) as temp_dir:
|
with TemporaryDirectory(dir=str(self.sys_config.path_tmp)) as temp_dir:
|
||||||
tar_file = Path(temp_dir, "snapshot.tar")
|
tar_file = Path(temp_dir, "snapshot.tar")
|
||||||
|
reader = await request.multipart()
|
||||||
|
contents = await reader.next()
|
||||||
try:
|
try:
|
||||||
with tar_file.open("wb") as snapshot:
|
with tar_file.open("wb") as snapshot:
|
||||||
async for data in request.content.iter_any():
|
while True:
|
||||||
snapshot.write(data)
|
chunk = await contents.read_chunk()
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
snapshot.write(chunk)
|
||||||
|
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
_LOGGER.error("Can't write new snapshot file: %s", err)
|
_LOGGER.error("Can't write new snapshot file: %s", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user