mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-14 04:36:31 +00:00
Drop dead folder restore code (#5517)
The inner function _folder_restore has been converted to a Job with PR #4802. The inner function is no longer used. Drop this dead code.
This commit is contained in:
parent
578383411c
commit
e72c5a037b
@ -696,63 +696,6 @@ class Backup(JobGroup):
|
|||||||
"""Backup Supervisor data into backup."""
|
"""Backup Supervisor data into backup."""
|
||||||
success = True
|
success = True
|
||||||
|
|
||||||
async def _folder_restore(name: str) -> bool:
|
|
||||||
"""Intenal function to restore a folder."""
|
|
||||||
slug_name = name.replace("/", "_")
|
|
||||||
tar_name = Path(
|
|
||||||
self._tmp.name, f"{slug_name}.tar{'.gz' if self.compressed else ''}"
|
|
||||||
)
|
|
||||||
origin_dir = Path(self.sys_config.path_supervisor, name)
|
|
||||||
|
|
||||||
# Check if exists inside backup
|
|
||||||
if not tar_name.exists():
|
|
||||||
_LOGGER.warning("Can't find restore folder %s", name)
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Unmount any mounts within folder
|
|
||||||
bind_mounts = [
|
|
||||||
bound.bind_mount
|
|
||||||
for bound in self.sys_mounts.bound_mounts
|
|
||||||
if bound.bind_mount.local_where
|
|
||||||
and bound.bind_mount.local_where.is_relative_to(origin_dir)
|
|
||||||
]
|
|
||||||
if bind_mounts:
|
|
||||||
await asyncio.gather(
|
|
||||||
*[bind_mount.unmount() for bind_mount in bind_mounts]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Clean old stuff
|
|
||||||
if origin_dir.is_dir():
|
|
||||||
await remove_folder(origin_dir, content_only=True)
|
|
||||||
|
|
||||||
# Perform a restore
|
|
||||||
def _restore() -> bool:
|
|
||||||
try:
|
|
||||||
_LOGGER.info("Restore folder %s", name)
|
|
||||||
with SecureTarFile(
|
|
||||||
tar_name,
|
|
||||||
"r",
|
|
||||||
key=self._key,
|
|
||||||
gzip=self.compressed,
|
|
||||||
bufsize=BUF_SIZE,
|
|
||||||
) as tar_file:
|
|
||||||
tar_file.extractall(
|
|
||||||
path=origin_dir, members=tar_file, filter="fully_trusted"
|
|
||||||
)
|
|
||||||
_LOGGER.info("Restore folder %s done", name)
|
|
||||||
except (tarfile.TarError, OSError) as err:
|
|
||||||
_LOGGER.warning("Can't restore folder %s: %s", name, err)
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
try:
|
|
||||||
return await self.sys_run_in_executor(_restore)
|
|
||||||
finally:
|
|
||||||
if bind_mounts:
|
|
||||||
await asyncio.gather(
|
|
||||||
*[bind_mount.mount() for bind_mount in bind_mounts]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Restore folder sequential avoid issue on slow IO
|
# Restore folder sequential avoid issue on slow IO
|
||||||
for folder in folder_list:
|
for folder in folder_list:
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user