Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
uberzzr committed Mar 16, 2023
1 parent ef7fd39 commit 3b8682f
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions bazelisk.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ def download_bazel_into_directory(version, is_commit, directory):

sha256_path = destination_path + ".sha256"
expected_hash = ""
matcher=re.compile(r"(\d*\.\d*(?:\.\d*)?)(rc\d+)?")
matched=matcher.match(version)
if not os.path.exists(sha256_path):
try:
download(bazel_url + ".sha256", sha256_path)
Expand All @@ -314,21 +316,20 @@ def download_bazel_into_directory(version, is_commit, directory):
sys.stderr.write(
"The Bazel mirror does not have a checksum file; skipping checksum verification."
)
if "https://releases.bazel.build" not in bazel_url:
matched=re.match(r"(\d*\.\d*(?:\.\d*)?)(rc\d+)?", version)
if matched:
(version, rc) = matched.groups()
fallback_url="https://releases.bazel.build/{}/{}/{}".format(
version, rc if rc else "release", bazel_filename
)
download(fallback_url+".sha256", sha256_path)
if "https://releases.bazel.build" in bazel_url or not matched:
return destination_path
if matched:
(version, rc) = matched.groups()
fallback_url="https://releases.bazel.build/{}/{}/{}".format(
version, rc if rc else "release", bazel_filename
)
try:
download("{}.sha256".format(fallback_url), sha256_path)
os.remove(destination_path)
download(fallback_url,destination_path)
os.chmod(destination_path, 0o755)
else:
except HTTPError:
return destination_path
else:
return destination_path
os.chmod(destination_path, 0o755)
raise e
with open(sha256_path, "r") as sha_file:
expected_hash = sha_file.read().split()[0]
Expand All @@ -339,20 +340,22 @@ def download_bazel_into_directory(version, is_commit, directory):
actual_hash = sha256_hash.hexdigest()
if actual_hash != expected_hash:
os.remove(sha256_path)
os.remove(destination_path)
print(
"The downloaded Bazel binary is corrupted. Expected SHA-256 {}, got {}. Fallback to default releases.bazel.build url.".format(
expected_hash, actual_hash
)
)
matched=re.match(r"(\d*\.\d*(?:\.\d*)?)(rc\d+)?", version)
if matched:
(version, rc) = matched.groups()
fallback_url="https://releases.bazel.build/{}/{}/{}".format(
version, rc if rc else "release", bazel_filename
)
download(fallback_url+".sha256", sha256_path)
os.remove(destination_path)
download(fallback_url,destination_path)
try:
download("{}.sha256".format(fallback_url), sha256_path)
download(fallback_url,destination_path)
except HTTPError:
exit(22)
os.chmod(destination_path, 0o755)
return destination_path

Expand Down

0 comments on commit 3b8682f

Please sign in to comment.