|
9 | 9 | import argparse
|
10 | 10 | import os
|
11 | 11 | import platform
|
| 12 | +import ssl |
12 | 13 | import stat
|
13 | 14 | import sys
|
14 | 15 | import urllib.request
|
|
18 | 19 | from typing import Sequence, Union
|
19 | 20 |
|
20 | 21 | import buck_util
|
| 22 | +import certifi |
21 | 23 | import zstd
|
22 | 24 |
|
23 | 25 | """
|
@@ -201,26 +203,23 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
|
201 | 203 | if os.path.isfile(buck2_local_path):
|
202 | 204 | return buck2_local_path
|
203 | 205 |
|
204 |
| - buck2_archive_url = f"https://github.com/facebook/buck2/releases/download/{target_buck_version}/{buck_info.archive_name}" |
| 206 | + buck2_archive_url = f"https://github.com/facebook/buck2/releases/download/{target_buck_version}/{buck_info.archive_name}" |
205 | 207 |
|
206 |
| - try: |
207 |
| - print(f"Downloading buck2 from {buck2_archive_url}...", file=sys.stderr) |
208 |
| - archive_file, _ = urllib.request.urlretrieve(buck2_archive_url) |
| 208 | + print(f"Downloading buck2 from {buck2_archive_url}...", file=sys.stderr) |
| 209 | + ssl_context = ssl.create_default_context(cafile=certifi.where()) |
209 | 210 |
|
210 |
| - # Extract and chmod. |
211 |
| - with open(archive_file, "rb") as f: |
212 |
| - data = f.read() |
213 |
| - decompressed_bytes = zstd.decompress(data) |
| 211 | + with urllib.request.urlopen(buck2_archive_url, context=ssl_context) as request: |
| 212 | + # Extract and chmod. |
| 213 | + data = request.read() |
| 214 | + decompressed_bytes = zstd.decompress(data) |
214 | 215 |
|
215 |
| - with open(buck2_local_path, "wb") as f: |
216 |
| - f.write(decompressed_bytes) |
| 216 | + with open(buck2_local_path, "wb") as f: |
| 217 | + f.write(decompressed_bytes) |
217 | 218 |
|
218 |
| - file_stat = os.stat(buck2_local_path) |
219 |
| - os.chmod(buck2_local_path, file_stat.st_mode | stat.S_IEXEC) |
220 |
| - finally: |
221 |
| - os.remove(archive_file) |
| 219 | + file_stat = os.stat(buck2_local_path) |
| 220 | + os.chmod(buck2_local_path, file_stat.st_mode | stat.S_IEXEC) |
222 | 221 |
|
223 |
| - return buck2_local_path |
| 222 | + return buck2_local_path |
224 | 223 |
|
225 | 224 |
|
226 | 225 | def main():
|
|
0 commit comments