mirror of
https://github.com/modelscope/modelscope.git
synced 2026-02-24 20:19:51 +01:00
optional hash
This commit is contained in:
@@ -29,6 +29,7 @@ API_RESPONSE_FIELD_MESSAGE = 'Message'
|
||||
MODELSCOPE_CLOUD_ENVIRONMENT = 'MODELSCOPE_ENVIRONMENT'
|
||||
MODELSCOPE_CLOUD_USERNAME = 'MODELSCOPE_USERNAME'
|
||||
MODELSCOPE_SDK_DEBUG = 'MODELSCOPE_SDK_DEBUG'
|
||||
MODELSCOPE_ENABLE_DEFAULT_HASH_VALIDATION = 'MODELSCOPE_ENABLE_DEFAULT_HASH_VALIDATION'
|
||||
ONE_YEAR_SECONDS = 24 * 365 * 60 * 60
|
||||
MODELSCOPE_REQUEST_ID = 'X-Request-ID'
|
||||
TEMPORARY_FOLDER_NAME = '._____temp'
|
||||
|
||||
@@ -12,6 +12,10 @@ from modelscope.hub.utils.utils import compute_hash
|
||||
from modelscope.utils.logger import get_logger
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
enable_default_hash_validation = \
|
||||
os.getenv(MODELSCOPE_ENABLE_DEFAULT_HASH_VALIDATION, 'False').strip().lower() == 'true'
|
||||
|
||||
"""Implements caching functionality, used internally only
|
||||
"""
|
||||
|
||||
@@ -274,7 +278,11 @@ class ModelFileSystemCache(FileSystemCache):
|
||||
expected_hash = model_file_info[FILE_HASH]
|
||||
if expected_hash is not None and os.path.exists(
|
||||
cache_file_path):
|
||||
cache_file_sha256 = compute_hash(cache_file_path)
|
||||
# compute hash only when enabled, otherwise just meet expectation by default
|
||||
if enable_default_hash_validation:
|
||||
cache_file_sha256 = compute_hash(cache_file_path)
|
||||
else:
|
||||
cache_file_sha256 = expected_hash
|
||||
if expected_hash == cache_file_sha256:
|
||||
is_exists = True
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user