apt: ensure we always drop CDROM info from sources.list

Back when sources.list was always present, we would:
 * move the contents of sources.list to sources.list.d/original.list
 * write the CDROM info to sources.list so the CDROM cat be used as an
   APT source
 * restore the original sources.list file when .deconfigure() is called,
   effectively discarding CDROM info

Nowadays, there is no guarantee that sources.list exists. So restoring
the contents of sources.list may mean deleting sources.list if it wasn't
present in the first place.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2024-01-22 12:25:35 +01:00
parent 3064343f45
commit 9b612dac34
1 changed files with 3 additions and 1 deletions

View File

@ -327,8 +327,10 @@ class AptConfigurer:
# The file only exists if we are online
with contextlib.suppress(FileNotFoundError):
os.unlink(target_mnt.p("etc/apt/sources.list.d/original.list"))
with contextlib.suppress(FileNotFoundError):
try:
_restore_file("etc/apt/sources.list")
except FileNotFoundError:
os.unlink(target_mnt.p("etc/apt/sources.list"))
with contextlib.suppress(FileNotFoundError):
_restore_file("etc/apt/apt.conf.d/90curtin-aptproxy")