From c96694105cbcc9234c206d7221255dfd898e5d52 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 20 Jul 2017 16:10:56 +0200 Subject: [PATCH] Handle broken appliance files Fix #1135 --- gns3server/controller/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py index 1b985ea4..e6cf25c1 100644 --- a/gns3server/controller/__init__.py +++ b/gns3server/controller/__init__.py @@ -71,10 +71,15 @@ class Controller: ): if os.path.isdir(directory): for file in os.listdir(directory): + if not file.endswith('.gns3a') and not file.endswith('.gns3appliance'): + continue path = os.path.join(directory, file) appliance_id = uuid.uuid3(uuid.NAMESPACE_URL, path) # Generate the UUID from path to avoid change between reboots - with open(path, 'r', encoding='utf-8') as f: - appliance = ApplianceTemplate(appliance_id, json.load(f), builtin=builtin) + try: + with open(path, 'r', encoding='utf-8') as f: + appliance = ApplianceTemplate(appliance_id, json.load(f), builtin=builtin) + except (ValueError, OSError) as e: + log.warning("Can't load %s: %s", path, str(e)) if appliance.status != 'broken': self._appliance_templates[appliance.id] = appliance