MCPcopy Create free account
hub / github.com/modelscope/modelscope / file_integrity_validation

Function file_integrity_validation

modelscope/hub/utils/utils.py:261–279  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

259
260
261def 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
282def add_content_to_file(repo,

Callers

nothing calls this directly

Calls 2

compute_hashFunction · 0.85
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…