From 174e7afdd00f012027228c7fa359db716ad021d9 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Tue, 20 Jun 2023 19:08:42 +0200 Subject: [PATCH] apt: reset only diverted files on deconfigure Before starting the actual installation, we make changes to etc/apt directory in an overlay so that the packages are pulled from the media instead of the network. At the end of installation, we need to revert these changes. We used to replace the etc/apt directory on the target by the etc/apt directory from the configured overlay. This is a simple way to revert the temporary changes. Unfortunately, it also removes configuration files that extra packages may have installed in etc/apt. For instance, when installing an OEM meta-package, a etc/apt/sources.list.d/.list gets installed. If we reset etc/apt to its content from the configured overlay, we lose this file. Fixed by selectively discarding changes to the files that subiquity modified. Signed-off-by: Olivier Gayot --- subiquity/server/apt.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/subiquity/server/apt.py b/subiquity/server/apt.py index 269a862b5..71f7450b5 100644 --- a/subiquity/server/apt.py +++ b/subiquity/server/apt.py @@ -99,8 +99,10 @@ class AptConfigurer: # # 1. Removing /cdrom from the installed system. # - # 2. Copying /etc/apt from the 'configured' overlay to the installed - # system. + # 2. Copying a set of diverted /etc/apt files from the 'configured' overlay + # to the installed system. Some packages such as OEM meta-packages and + # keyrings will install files in /etc/apt so we cannot simply discard + # everything. # # 3. If the network is working, run apt-get update in the installed # system, or if it is not, just copy /var/lib/apt/lists from the @@ -288,7 +290,16 @@ async def _restore_dir(dir): 'cp', '-aT', self.configured_tree.p(dir), target_mnt.p(dir), ]) - await _restore_dir('etc/apt') + def _restore_file(path: str) -> None: + shutil.copyfile(self.configured_tree.p(path), target_mnt.p(path)) + + # The file only exists if we are online + with contextlib.suppress(FileNotFoundError): + os.unlink(target_mnt.p('etc/apt/sources.list.d/original.list')) + _restore_file('etc/apt/sources.list') + + with contextlib.suppress(FileNotFoundError): + _restore_file('etc/apt/apt.conf.d/90curtin-aptproxy') if self.app.base_model.network.has_network: await run_curtin_command(