From 24c28a89c2f5b27e9793c8151312f9d3a457780d Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Tue, 11 Oct 2022 15:44:25 -0600 Subject: [PATCH] apt: workaround umount failure When the apt overlay fails to umount, this directory removal will also fail due to the mount still being present. LP: #1992531 --- subiquity/server/apt.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/subiquity/server/apt.py b/subiquity/server/apt.py index fe4cdc247..e30777021 100644 --- a/subiquity/server/apt.py +++ b/subiquity/server/apt.py @@ -251,7 +251,10 @@ async def cleanup(self): for m in reversed(self._mounts): await self.unmount(m, remove=False) for d in self._tdirs: - shutil.rmtree(d) + try: + shutil.rmtree(d) + except OSError as ose: + log.warning(f'failed to rmtree {d}: {ose}') async def deconfigure(self, context, target: str) -> None: target_mnt = Mountpoint(mountpoint=target) @@ -272,7 +275,11 @@ async def _restore_dir(dir): await _restore_dir('var/lib/apt/lists') await self.cleanup() - os.rmdir(target_mnt.p('cdrom')) + try: + d = target_mnt.p('cdrom') + os.rmdir(d) + except OSError as ose: + log.warning(f'failed to rmdir {d}: {ose}') async def setup_target(self, context, target: str): # Call this after the rootfs has been extracted to the real target