mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 17:55:27 +00:00
[models/utils] Catch and log exception when opening file fails
This commit is contained in:
parent
e9a959e3a7
commit
1ac1875a86
|
@ -137,3 +137,4 @@ class VerifyResult(Enum):
|
||||||
HASH_MATCH = 0
|
HASH_MATCH = 0
|
||||||
HASH_MISMATCH = 1
|
HASH_MISMATCH = 1
|
||||||
FILE_MISSING = 2
|
FILE_MISSING = 2
|
||||||
|
OTHER_ERROR = 3
|
||||||
|
|
|
@ -50,9 +50,10 @@ def validate_files(base_path: str, filelist: List[tuple], hash_type='sha1') -> I
|
||||||
yield VerifyResult.FILE_MISSING, file_path, ''
|
yield VerifyResult.FILE_MISSING, file_path, ''
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
with open(full_path, 'rb') as f:
|
with open(full_path, 'rb') as f:
|
||||||
real_file_hash = hashlib.new(hash_type)
|
real_file_hash = hashlib.new(hash_type)
|
||||||
while chunk := f.read(8192):
|
while chunk := f.read(1024*1024):
|
||||||
real_file_hash.update(chunk)
|
real_file_hash.update(chunk)
|
||||||
|
|
||||||
result_hash = real_file_hash.hexdigest()
|
result_hash = real_file_hash.hexdigest()
|
||||||
|
@ -60,6 +61,9 @@ def validate_files(base_path: str, filelist: List[tuple], hash_type='sha1') -> I
|
||||||
yield VerifyResult.HASH_MISMATCH, file_path, result_hash
|
yield VerifyResult.HASH_MISMATCH, file_path, result_hash
|
||||||
else:
|
else:
|
||||||
yield VerifyResult.HASH_MATCH, file_path, result_hash
|
yield VerifyResult.HASH_MATCH, file_path, result_hash
|
||||||
|
except Exception as e:
|
||||||
|
logger.fatal(f'Could not verify "{file_path}"; opening failed with: {e!r}')
|
||||||
|
yield VerifyResult.OTHER_ERROR, file_path, ''
|
||||||
|
|
||||||
|
|
||||||
def clean_filename(filename):
|
def clean_filename(filename):
|
||||||
|
|
Loading…
Reference in a new issue