Skip to content

Commit

Permalink
Drop dead folder restore code (#5517)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agners authored Dec 31, 2024
1 parent 5783834 commit e72c5a0
Showing 1 changed file with 0 additions and 57 deletions.
57 changes: 0 additions & 57 deletions supervisor/backups/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,63 +696,6 @@ async def restore_folders(self, folder_list: list[str]) -> bool:
"""Backup Supervisor data into backup."""
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
for folder in folder_list:
try:
Expand Down

0 comments on commit e72c5a0

Please sign in to comment.