Fix content.json modified float decimals on Android
This commit is contained in:
parent
8ef7e0a772
commit
3afca90c0e
2 changed files with 17 additions and 0 deletions
|
@ -55,6 +55,11 @@ class Config(object):
|
|||
|
||||
use_openssl = True
|
||||
|
||||
if repr(1483108852.565) != "1483108852.565":
|
||||
fix_float_decimals = True
|
||||
else:
|
||||
fix_float_decimals = False
|
||||
|
||||
# Main
|
||||
action = self.subparsers.add_parser("main", help='Start UiServer and FileServer (default)')
|
||||
|
||||
|
@ -173,6 +178,8 @@ class Config(object):
|
|||
type='bool', choices=[True, False], default=False)
|
||||
self.parser.add_argument("--msgpack_purepython", help='Use less memory, but a bit more CPU power',
|
||||
type='bool', choices=[True, False], default=True)
|
||||
self.parser.add_argument("--fix_float_decimals", help='Fix content.json modification date float precision on verification',
|
||||
type='bool', choices=[True, False], default=fix_float_decimals)
|
||||
|
||||
self.parser.add_argument('--coffeescript_compiler', help='Coffeescript compiler for developing', default=coffeescript,
|
||||
metavar='executable_path')
|
||||
|
|
|
@ -768,8 +768,18 @@ class ContentManager(object):
|
|||
del(new_content["sign"]) # The file signed without the sign
|
||||
if "signs" in new_content:
|
||||
del(new_content["signs"]) # The file signed without the signs
|
||||
|
||||
sign_content = json.dumps(new_content, sort_keys=True) # Dump the json to string to remove whitepsace
|
||||
|
||||
# Fix float representation error on Android
|
||||
modified = new_content["modified"]
|
||||
if config.fix_float_decimals and type(modified) is float and not str(modified).endswith(".0"):
|
||||
modified_fixed = "{:.6f}".format(modified).strip("0.")
|
||||
sign_content = sign_content.replace(
|
||||
'"modified": %s' % repr(modified),
|
||||
'"modified": %s' % modified_fixed
|
||||
)
|
||||
|
||||
if not self.verifyContent(inner_path, new_content):
|
||||
return False # Content not valid (files too large, invalid files)
|
||||
|
||||
|
|
Loading…
Reference in a new issue