diff --git a/src/Config.py b/src/Config.py index d465aaa2..7451b513 100644 --- a/src/Config.py +++ b/src/Config.py @@ -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') diff --git a/src/Content/ContentManager.py b/src/Content/ContentManager.py index 9e6725a0..1b425316 100644 --- a/src/Content/ContentManager.py +++ b/src/Content/ContentManager.py @@ -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)