ContentManager: split verifyFile() into 2 functions and always log the verify error at INFO level

This commit is contained in:
Vadim Ushakov 2020-11-04 18:22:14 +07:00
parent 7354d712e0
commit 5d5b3684cc

View file

@ -925,12 +925,9 @@ class ContentManager(object):
return True # All good
# Verify file validity
# Return: None = Same as before, False = Invalid, True = Valid
def verifyFile(self, inner_path, file, ignore_same=True):
if inner_path.endswith("content.json"): # content.json: Check using sign
def verifyContentJson(self, inner_path, file, ignore_same=True):
from Crypt import CryptBitcoin
try:
if type(file) is dict:
new_content = file
else:
@ -1001,11 +998,7 @@ class ContentManager(object):
else: # Old style signing
raise VerifyError("Invalid old-style sign")
except Exception as err:
self.log.warning("%s: verify sign error: %s" % (inner_path, Debug.formatException(err)))
raise err
else: # Check using sha512 hash
def verifyOrdinaryFile(self, inner_path, file, ignore_same=True):
file_info = self.getFileInfo(inner_path)
if file_info:
if CryptHash.sha512sum(file) != file_info.get("sha512", ""):
@ -1022,6 +1015,18 @@ class ContentManager(object):
else: # File not in content.json
raise VerifyError("File not in content.json")
# Verify file validity
# Return: None = Same as before, False = Invalid, True = Valid
def verifyFile(self, inner_path, file, ignore_same=True):
try:
if inner_path.endswith("content.json"):
return self.verifyContentJson(inner_path, file, ignore_same)
else:
return self.verifyOrdinaryFile(inner_path, file, ignore_same)
except Exception as err:
self.log.info("%s: verify error: %s" % (inner_path, Debug.formatException(err)))
raise err
def optionalDelete(self, inner_path):
self.site.storage.delete(inner_path)