From 9987fccdfc113670e323f40a58f22c69328833a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Thu, 12 Mar 2015 17:06:17 +0000 Subject: morphlib/sourceresolver.py: Fail if morph doesnt support the version of definitions format This patch will add the following restriction: if VERSION exist and its a YAML file and its a dict and has the key 'version' and the type stored in the 'version' key is an int and that int is not in the supported format, then fail. So, if someone is using 'version: 4' in VERSION, morph will fail (as opposed to current morph, that will not fail in the check but will likely fail when it tries to compile) Change-Id: I555f7e6018b9bdf18c80039df92a253acbd51c8c --- morphlib/sourceresolver.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/morphlib/sourceresolver.py b/morphlib/sourceresolver.py index d2b47d35..97d3e422 100644 --- a/morphlib/sourceresolver.py +++ b/morphlib/sourceresolver.py @@ -31,7 +31,7 @@ tree_cache_filename = 'trees.cache.pickle' buildsystem_cache_size = 10000 buildsystem_cache_filename = 'detected-chunk-buildsystems.cache.pickle' -not_supported_versions = [] +supported_versions = [0, 1] class PickleCacheManager(object): # pragma: no cover '''Cache manager for PyLRU that reads and writes to Pickle files. @@ -354,13 +354,17 @@ class SourceResolver(object): if version_file is None: return - try: - version = yaml.safe_load(version_file)['version'] - except (yaml.error.YAMLError, KeyError, TypeError): - version = 0 - - if version in not_supported_versions: - raise UnknownVersionError(version) + version = None + yaml_obj = yaml.safe_load(version_file) + if yaml_obj is not None: + if type(yaml_obj) is dict: + if 'version' in yaml_obj.keys(): + if type(yaml_obj['version']) is int: + version = yaml_obj['version'] + + if version is not None: + if version not in supported_versions: + raise UnknownVersionError(version) def _process_definitions_with_children(self, system_filenames, definitions_repo, -- cgit v1.2.1