Skip to content

Commit

Permalink
AptTool: add repo key before running apt-add-repository (#8861)
Browse files Browse the repository at this point in the history
In Ubuntu 20.04 (and maybe earlier), the behavior of

    apt-add-repository 'deb https://example.com/repo example main'

is to add the named repository to apt's sources *and* to update the
package index.  If the new repository's package key is not already in
apt's keyring, this will fail.

It is possible to change this behavior by running apt-add-repository -n,
but adding the key before running apt-add-repository also works, doesn't
require new command-line switches, and should be backwards-compatible
with apt-add-repository versions that might not behave as described
above.
  • Loading branch information
hannahwhy committed May 10, 2021
1 parent 8702dd2 commit c2ad720
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions conans/client/tools/system_pm.py
Expand Up @@ -272,11 +272,11 @@ def installed(self, package_name):

class AptTool(BaseTool):
def add_repository(self, repository, repo_key=None):
_run(self._runner, "%sapt-add-repository %s" % (self._sudo_str, repository),
output=self._output)
if repo_key:
_run(self._runner, "wget -qO - %s | %sapt-key add -" % (repo_key, self._sudo_str),
output=self._output)
_run(self._runner, "%sapt-add-repository %s" % (self._sudo_str, repository),
output=self._output)

def update(self):
_run(self._runner, "%sapt-get update" % self._sudo_str, output=self._output)
Expand Down
2 changes: 1 addition & 1 deletion conans/test/unittests/client/tools/system_pm_test.py
Expand Up @@ -100,10 +100,10 @@ def _run_add_repository_test(repository, gpg_key, sudo, isatty, update):
sudo_cmd = "sudo " if isatty else "sudo -A "

runner = RunnerOrderedMock()
runner.commands.append(("{}apt-add-repository {}".format(sudo_cmd, repository), 0))
if gpg_key:
runner.commands.append(
("wget -qO - {} | {}apt-key add -".format(gpg_key, sudo_cmd), 0))
runner.commands.append(("{}apt-add-repository {}".format(sudo_cmd, repository), 0))
if update:
runner.commands.append(("{}apt-get update".format(sudo_cmd), 0))

Expand Down

0 comments on commit c2ad720

Please sign in to comment.