From 79afdac89e11b0a6f5b3817bf2a9b8197a402e6c Mon Sep 17 00:00:00 2001 From: James Date: Tue, 7 Mar 2023 14:28:37 +0100 Subject: [PATCH] Define download sets (#13349) * define download sets * tests --- conans/client/rest/rest_client_v2.py | 16 +++++++++------- conans/test/integration/remote/rest_api_test.py | 10 ++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/conans/client/rest/rest_client_v2.py b/conans/client/rest/rest_client_v2.py index 50912d321a3..5ed09d3901e 100644 --- a/conans/client/rest/rest_client_v2.py +++ b/conans/client/rest/rest_client_v2.py @@ -1,6 +1,5 @@ import copy import os -import time from conan.api.output import ConanOutput @@ -32,15 +31,16 @@ def router(self): def _get_file_list_json(self, url): data = self.get_json(url) # Discarding (.keys()) still empty metadata for files - data["files"] = list(data["files"].keys()) + # and make sure the paths like metadata/sign/signature are normalized to / + data["files"] = list(d.replace("\\", "/") for d in data["files"].keys()) return data def get_recipe(self, ref, dest_folder): url = self.router.recipe_snapshot(ref) data = self._get_file_list_json(url) files = data["files"] - if EXPORT_SOURCES_TGZ_NAME in files: - files.remove(EXPORT_SOURCES_TGZ_NAME) + accepted_files = ["conanfile.py", "conan_export.tgz", "conanmanifest.txt", "metadata/sign"] + files = [f for f in files if any(f.startswith(m) for m in accepted_files)] # If we didn't indicated reference, server got the latest, use absolute now, it's safer urls = {fn: self.router.recipe_file(ref, fn) for fn in files} @@ -69,6 +69,9 @@ def get_package(self, pref, dest_folder): url = self.router.package_snapshot(pref) data = self._get_file_list_json(url) files = data["files"] + # Download only known files, but not metadata (except sign) + accepted_files = ["conaninfo.txt", "conan_package.tgz", "conanmanifest.txt", "metadata/sign"] + files = [f for f in files if any(f.startswith(m) for m in accepted_files)] # If we didn't indicated reference, server got the latest, use absolute now, it's safer urls = {fn: self.router.package_file(pref, fn) for fn in files} self._download_and_save_files(urls, dest_folder, files) @@ -108,7 +111,6 @@ def _upload_package(self, pref, files_to_upload): self._upload_files(files_to_upload, urls) def _upload_files(self, files, urls): - t1 = time.time() failed = [] uploader = FileUploader(self.requester, self.verify_ssl, self._config) # conan_package.tgz and conan_export.tgz are uploaded first to avoid uploading conaninfo.txt @@ -117,7 +119,7 @@ def _upload_files(self, files, urls): for filename in sorted(files): # As the filenames are sorted, the last one is always "conanmanifest.txt" if output and not output.is_terminal: - msg ="-> %s" % filename + msg = "-> %s" % filename output.info(msg) resource_url = urls[filename] try: @@ -276,7 +278,7 @@ def get_package_revisions_references(self, pref, headers=None): url = self.router.package_revisions(pref) tmp = self.get_json(url, headers=headers)["revisions"] remote_prefs = [PkgReference(pref.ref, pref.package_id, item.get("revision"), - from_iso8601_to_timestamp(item.get("time"))) for item in tmp] + from_iso8601_to_timestamp(item.get("time"))) for item in tmp] if pref.revision: # FIXME: This is a bit messy, is it checking the existance? or getting the time? or both? for _pref in remote_prefs: diff --git a/conans/test/integration/remote/rest_api_test.py b/conans/test/integration/remote/rest_api_test.py index 6e531d07310..1fbb30567c6 100644 --- a/conans/test/integration/remote/rest_api_test.py +++ b/conans/test/integration/remote/rest_api_test.py @@ -1,5 +1,4 @@ import os -import platform import unittest import pytest @@ -97,18 +96,17 @@ def test_get_package(self): # Get the package tmp_dir = temp_folder() self.api.get_package(pref, tmp_dir) - self.assertIn("hello.cpp", os.listdir(tmp_dir)) + # The hello.cpp file is not downloaded! + self.assertNotIn("hello.cpp", os.listdir(tmp_dir)) - @pytest.mark.skipif(platform.system() != "Linux", reason="only Linux") def test_upload_huge_conan(self): ref = RecipeReference.loads("conanhuge/1.0.0@private_user/testing#myreciperev") - files = {"file%s.cpp" % name: "File conent" for name in range(10)} - self._upload_recipe(ref, files) + self._upload_recipe(ref, {"file9.cpp": ""}) tmp = temp_folder() files = self.api.get_recipe(ref, tmp) self.assertIsNotNone(files) - self.assertTrue(os.path.exists(os.path.join(tmp, "file9.cpp"))) + self.assertFalse(os.path.exists(os.path.join(tmp, "file9.cpp"))) def test_search(self): # Upload a conan1