Skip to content

Commit

Permalink
fetch-cargo-vendor: allow retries for 10 times
Browse files Browse the repository at this point in the history
  • Loading branch information
Bot-wxt1221 committed Nov 19, 2024
1 parent 5db4993 commit 04dd678
Showing 1 changed file with 10 additions and 1 deletion.
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)
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

0 comments on commit 04dd678

Please sign in to comment.