From c2ad7201f0c67c403e9d9257b6b95a0a30744106 Mon Sep 17 00:00:00 2001 From: yipdw Date: Mon, 10 May 2021 07:04:08 -0500 Subject: [PATCH] AptTool: add repo key before running apt-add-repository (#8861) 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. --- conans/client/tools/system_pm.py | 4 ++-- conans/test/unittests/client/tools/system_pm_test.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conans/client/tools/system_pm.py b/conans/client/tools/system_pm.py index 0821dba3e54..5a3760c5d02 100644 --- a/conans/client/tools/system_pm.py +++ b/conans/client/tools/system_pm.py @@ -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) diff --git a/conans/test/unittests/client/tools/system_pm_test.py b/conans/test/unittests/client/tools/system_pm_test.py index 63267cd522c..dbd5896fe3f 100644 --- a/conans/test/unittests/client/tools/system_pm_test.py +++ b/conans/test/unittests/client/tools/system_pm_test.py @@ -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))