Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkgs/build-support/rust/fetch-cargo-vendor-util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ def load_toml(path: Path) -> dict[str, Any]:
return tomllib.load(f)


def get_response(url):
for _ in range(10): # Retry if the request fails
try:
response = requests.get(url, stream=True)
Copy link
Member

Choose a reason for hiding this comment

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

Please add some timeout i.e. exponential backoff as well so we are not overloading crates.io with requests in case they are overloaded.

return response
except requests.exceptions.RequestException:
pass


def download_file_with_checksum(url: str, destination_path: Path) -> str:
sha256_hash = hashlib.sha256()
with requests.get(url, stream=True) as response:
with get_response(url) as response:
if not response.ok:
raise Exception(f"Failed to fetch file from {url}. Status code: {response.status_code}")
with open(destination_path, "wb") as file:
Expand Down