Validate the file hash is expected, if not, delete the file Args: file_path (str): The file to validate expected_sha256 (str): The expected sha256 hash Returns: bool: True if the file is valid, False otherwise
(file_path, expected_sha256)
| 259 | |
| 260 | |
| 261 | def file_integrity_validation(file_path, expected_sha256) -> bool: |
| 262 | """Validate the file hash is expected, if not, delete the file |
| 263 | |
| 264 | Args: |
| 265 | file_path (str): The file to validate |
| 266 | expected_sha256 (str): The expected sha256 hash |
| 267 | |
| 268 | Returns: |
| 269 | bool: True if the file is valid, False otherwise |
| 270 | """ |
| 271 | file_sha256 = compute_hash(file_path) |
| 272 | if not file_sha256 == expected_sha256: |
| 273 | os.remove(file_path) |
| 274 | msg = 'File %s integrity check failed, expected sha256 signature is %s, actual is %s, the download may be incomplete, please try again.' % ( # noqa E501 |
| 275 | file_path, expected_sha256, file_sha256) |
| 276 | logger.error(msg) |
| 277 | return False |
| 278 | |
| 279 | return True |
| 280 | |
| 281 | |
| 282 | def add_content_to_file(repo, |
nothing calls this directly
no test coverage detected
searching dependent graphs…