|
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 Union
|
19 | 20 |
|
20 | 21 | import buck_util
|
| 22 | +import certifi |
21 | 23 | import zstd
|
22 | 24 |
|
23 | 25 | """
|
@@ -179,26 +181,23 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
|
179 | 181 | if os.path.isfile(buck2_local_path):
|
180 | 182 | return buck2_local_path
|
181 | 183 |
|
182 |
| - buck2_archive_url = f"https://github.com/facebook/buck2/releases/download/{target_buck_version}/{buck_info.archive_name}" |
| 184 | + buck2_archive_url = f"https://github.com/facebook/buck2/releases/download/{target_buck_version}/{buck_info.archive_name}" |
183 | 185 |
|
184 |
| - try: |
185 |
| - print(f"Downloading buck2 from {buck2_archive_url}...", file=sys.stderr) |
186 |
| - archive_file, _ = urllib.request.urlretrieve(buck2_archive_url) |
| 186 | + print(f"Downloading buck2 from {buck2_archive_url}...", file=sys.stderr) |
| 187 | + ssl_context = ssl.create_default_context(cafile=certifi.where()) |
187 | 188 |
|
188 |
| - # Extract and chmod. |
189 |
| - with open(archive_file, "rb") as f: |
190 |
| - data = f.read() |
191 |
| - decompressed_bytes = zstd.decompress(data) |
| 189 | + with urllib.request.urlopen(buck2_archive_url, context=ssl_context) as request: |
| 190 | + # Extract and chmod. |
| 191 | + data = request.read() |
| 192 | + decompressed_bytes = zstd.decompress(data) |
192 | 193 |
|
193 |
| - with open(buck2_local_path, "wb") as f: |
194 |
| - f.write(decompressed_bytes) |
| 194 | + with open(buck2_local_path, "wb") as f: |
| 195 | + f.write(decompressed_bytes) |
195 | 196 |
|
196 |
| - file_stat = os.stat(buck2_local_path) |
197 |
| - os.chmod(buck2_local_path, file_stat.st_mode | stat.S_IEXEC) |
198 |
| - finally: |
199 |
| - os.remove(archive_file) |
| 197 | + file_stat = os.stat(buck2_local_path) |
| 198 | + os.chmod(buck2_local_path, file_stat.st_mode | stat.S_IEXEC) |
200 | 199 |
|
201 |
| - return buck2_local_path |
| 200 | + return buck2_local_path |
202 | 201 |
|
203 | 202 |
|
204 | 203 | def main():
|
|
0 commit comments