Skip to content

Commit

Permalink
Define download sets (#13349)
Browse files Browse the repository at this point in the history
* define download sets

* tests
  • Loading branch information
memsharded authored Mar 7, 2023
1 parent d2b2a25 commit 79afdac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 9 additions & 7 deletions conans/client/rest/rest_client_v2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import copy
import os
import time

from conan.api.output import ConanOutput

Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 4 additions & 6 deletions conans/test/integration/remote/rest_api_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import platform
import unittest

import pytest
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 79afdac

Please sign in to comment.