mirror of https://github.com/mongodb/mongo
SERVER-107933 fix download.py on windows (#38901)
GitOrigin-RevId: 16f20e71049a4a5bf500c23325020b31547f73ab
This commit is contained in:
parent
fa4f723f6c
commit
081d8dcaaa
|
|
@ -71,10 +71,6 @@ def install_bazel(binary_directory: str) -> str:
|
|||
is_bazelisk_supported = normalized_arch not in ["ppc64le", "s390x"]
|
||||
binary_filename = "bazelisk"
|
||||
binary_path = os.path.join(binary_directory, binary_filename)
|
||||
if os.path.exists(binary_path):
|
||||
print(f"{binary_filename} already exists ({binary_path}), skipping download")
|
||||
_set_bazel_permissions(binary_path)
|
||||
return binary_path
|
||||
|
||||
if is_bazelisk_supported:
|
||||
print(f"Downloading {binary_filename}...")
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
import argparse
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
|
@ -60,7 +61,6 @@ def _verify_s3_hash(s3_path: str, local_path: str, expected_hash: str) -> None:
|
|||
raise ValueError(
|
||||
f"Hash mismatch for {s3_path}, expected {expected_hash} but got {hash_string}"
|
||||
)
|
||||
print(f"File is valid: {local_path} (sha256: {expected_hash})")
|
||||
|
||||
def validate_file(s3_path, output_path, remote_sha_allowed):
|
||||
hexdigest = S3_SHA256_HASHES.get(s3_path)
|
||||
|
|
@ -99,6 +99,7 @@ def _download_and_verify(s3_path, output_path, remote_sha_allowed):
|
|||
download_from_s3_with_requests(s3_path, output_path)
|
||||
|
||||
validate_file(s3_path, output_path, remote_sha_allowed)
|
||||
break
|
||||
|
||||
except Exception:
|
||||
print("Download failed:")
|
||||
|
|
@ -131,7 +132,15 @@ def download_s3_binary(
|
|||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||
tempfile_name = temp_file.name
|
||||
_download_and_verify(s3_path, tempfile_name, remote_sha_allowed)
|
||||
|
||||
try:
|
||||
os.replace(tempfile_name, local_path)
|
||||
except OSError as e:
|
||||
if e.errno == 18: # EXDEV cross filesystem error, need to use a mv
|
||||
shutil.move(tempfile_name, local_path)
|
||||
else:
|
||||
raise
|
||||
|
||||
print(f"Downloaded and verified {s3_path} -> {local_path}")
|
||||
return True
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Reference in New Issue