#1043101 apt-add-repository does not work when there are no .list files

#1043101#5
Date:
2023-08-06 04:29:40 UTC
From:
To:
The command apt-add-repository does not work correctly when there are no
.list files on the system. Either /etc/apt/sources.list or any .list
file in /etc/apt/sources.list.d/ with at least one line in it (this can
be a comment) is required for the command to work.

The Debian bookworm docker images (debian:bookworm and
debian:bookworm-slim) ship with no .list files. The default repository
is configured in /etc/apt/sources.list.d/debian.sources. Debian bullseye
ships with .list files and does not have this issue.

This will break some CI pipelines that use the bookworm docker images
and later use apt-add-repository. An example of this is the LLVM install
script (https://apt.llvm.org/#llvmsh)

The workaround is to create a /etc/apt/sources.list file (even with only
1 comment line) or add a .list file to /etc/apt/sources.list.d/

A low risk fix is to have add-apt-repository create the
/etc/apt/sources.list if there are no (.list) sources. The save()
function already does this. (see patch below)

See https://github.com/hof/bookworm-apt-add-repository-issue for examples.

Regards,
Erik
--- apt-add-repository-0.99.30-4
+++ apt-add-repository
@@ -36,6 +36,9 @@
          gettext.textdomain("software-properties")
          self.distro = get_distro()
          self.sourceslist = SourcesList()
+        if len(self.sourceslist.list) == 0:
+            self.sourceslist.save()
+            self.sourceslist = SourcesList()
          self.distro.get_sources(self.sourceslist)

      def parse_args(self, args):