Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to avoid touching remote when binary not found in -r=remote #9355

Merged
merged 8 commits into from Aug 24, 2021
Merged
20 changes: 13 additions & 7 deletions conans/client/graph/graph_binaries.py
Expand Up @@ -100,9 +100,11 @@ def _evaluate_cache_pkg(self, node, package_layout, pref, metadata, remote, remo
def _get_package_info(self, node, pref, remote):
return self._remote_manager.get_package_info(pref, remote, info=node.conanfile.info)

def _evaluate_remote_pkg(self, node, pref, remote, remotes):
def _evaluate_remote_pkg(self, node, pref, remote, remotes, remote_selected):
remote_info = None
if remote:
# If the remote is pinned (remote_selected) we won't iterate the remotes.
# The "remote" can come from -r or from the registry (associated ref)
if remote_selected or remote:
try:
remote_info, pref = self._get_package_info(node, pref, remote)
except NotFoundException:
Expand All @@ -111,10 +113,12 @@ def _evaluate_remote_pkg(self, node, pref, remote, remotes):
node.conanfile.output.error("Error downloading binary package: '{}'".format(pref))
raise

# If the "remote" came from the registry but the user didn't specified the -r, with
# revisions iterate all remotes
if not remote or (not remote_info and self._cache.config.revisions_enabled):
for r in remotes.values(): # FIXME: Here we hit the same remote we did before
# If we didn't pin a remote with -r and we didn't find a package, we iterate the
# other remotes to find a binary but only when revisions mechanism
if not remote_selected and (not remote_info and self._cache.config.revisions_enabled):
for r in remotes.values():
if r == remote:
continue
try:
remote_info, pref = self._get_package_info(node, pref, r)
except NotFoundException:
Expand Down Expand Up @@ -243,6 +247,7 @@ def _process_node(self, node, pref, build_mode, update, remotes):
metadata = self._evaluate_clean_pkg_folder_dirty(node, package_layout, pref)

remote = remotes.selected
remote_selected = remote is not None

metadata = metadata or package_layout.load_metadata()
if not remote:
Expand All @@ -260,7 +265,8 @@ def _process_node(self, node, pref, build_mode, update, remotes):
recipe_hash = None
else: # Binary does NOT exist locally
# Returned remote might be different than the passed one if iterating remotes
recipe_hash, remote = self._evaluate_remote_pkg(node, pref, remote, remotes)
recipe_hash, remote = self._evaluate_remote_pkg(node, pref, remote, remotes,
remote_selected)

if build_mode.outdated:
if node.binary in (BINARY_CACHE, BINARY_DOWNLOAD, BINARY_UPDATE):
Expand Down
17 changes: 17 additions & 0 deletions conans/test/functional/revisions_test.py
Expand Up @@ -1598,3 +1598,20 @@ def test_necessary_update():
c.save({"conanfile.py": GenConanfile("app", "0.1").with_requires("pkg/0.1#{}".format(rrev2))})
c.run("install .")
assert rrev2 in c.out


def test_touching_other_server():
# https://github.com/conan-io/conan/issues/9333
servers = OrderedDict([("remote1", TestServer()),
("remote2", None)]) # None server will crash if touched
c = TestClient(servers=servers, users={"remote1": [("conan", "password")]})
c.run("config set general.revisions_enabled=True")
c.save({"conanfile.py": GenConanfile().with_settings("os")})
c.run("create . pkg/0.1@conan/channel -s os=Windows")
c.run("upload * --all -c -r=remote1")
c.run("remove * -f")

# This is OK, binary found
c.run("install pkg/0.1@conan/channel -r=remote1 -s os=Windows")
c.run("install pkg/0.1@conan/channel -r=remote1 -s os=Linux", assert_error=True)
assert "ERROR: Missing binary: pkg/0.1@conan/channel" in c.out
Expand Up @@ -290,6 +290,7 @@ def test_fail_usefully_when_failing_retrieving_package():
client.run("install {}".format(ref2), assert_error=True)
assert "ERROR: Error downloading binary package: '{}'".format(pref1) in client.out


def test_evil_insertions():
ref = ConanFileReference.loads("lib1/1.0@conan/stable")
ref2 = ConanFileReference.loads("lib2/1.0@conan/stable")
Expand Down
2 changes: 1 addition & 1 deletion conans/test/integration/remote/test_request_headers.py
Expand Up @@ -50,7 +50,7 @@ def setUp(self):

def _get_header(self, requester, header_name):
hits = sum([header_name in headers for _, headers in requester.requests])
assert hits == 2 if self.revs_enabled else 1
assert hits <= 2 if self.revs_enabled else 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the removed: # FIXME: Here we hit the same remote we did before

for url, headers in requester.requests:
if header_name in headers:
if self.revs_enabled:
Expand Down