|
7 | 7 | import os
|
8 | 8 | import shutil
|
9 | 9 | import sys
|
10 |
| -from pathlib import Path |
11 |
| -from pathlib import PurePath |
| 10 | +from pathlib import Path, PurePath |
12 | 11 |
|
13 |
| -from . import install_os |
14 |
| -from . import RESET_COLOR |
15 |
| -from . import suffix |
16 |
| -from . import YELLOW |
17 |
| -from .util import download_file |
| 12 | +from . import install_os, RESET_COLOR, suffix, YELLOW |
| 13 | +from .util import download_file, verify_sha512, get_sha_checksum |
18 | 14 |
|
19 | 15 |
|
20 | 16 | def clang_tools_binary_url(
|
@@ -46,14 +42,21 @@ def install_tool(tool_name: str, version: str, directory: str) -> bool:
|
46 | 42 | :returns: `True` if the binary had to be downloaded and installed.
|
47 | 43 | `False` if the binary was not downloaded but is installed in ``directory``.
|
48 | 44 | """
|
49 |
| - if Path(directory, f"{tool_name}-{version}{suffix}").exists(): |
50 |
| - print(f"{tool_name}-{version}", "already installed") |
51 |
| - return False |
| 45 | + destination = Path(directory, f"{tool_name}-{version}{suffix}") |
52 | 46 | bin_url = clang_tools_binary_url(tool_name, version)
|
53 |
| - bin_name = str(PurePath(bin_url).stem) |
| 47 | + if destination.exists(): |
| 48 | + print(f"{tool_name}-{version}", "already installed...") |
| 49 | + print(" checking SHA512...", end=" ") |
| 50 | + if verify_sha512(get_sha_checksum(bin_url), destination.read_bytes()): |
| 51 | + print("valid") |
| 52 | + return False |
| 53 | + print("invalid") |
54 | 54 | print("downloading", tool_name, f"(version {version})")
|
| 55 | + bin_name = str(PurePath(bin_url).stem) |
55 | 56 | download_file(bin_url, bin_name)
|
56 | 57 | move_and_chmod_bin(bin_name, f"{tool_name}-{version}{suffix}", directory)
|
| 58 | + if not verify_sha512(get_sha_checksum(bin_url), destination.read_bytes()): |
| 59 | + raise ValueError(f"file was corrupted during download from {bin_url}") |
57 | 60 | return True
|
58 | 61 |
|
59 | 62 |
|
|
0 commit comments