From 3fc64bced2df2d417681786de64fa4e37ddaf981 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 5 Feb 2016 10:29:27 +0100 Subject: [PATCH] Fix a crash if you create a file named IOS in the image dir Fix #419 --- gns3server/modules/dynamips/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index a246c564..ac5aef26 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -710,10 +710,12 @@ class Dynamips(BaseManager): """ image_dir = self.get_images_directory() + if not os.path.exists(image_dir): + return [] try: files = os.listdir(image_dir) - except FileNotFoundError: - return [] + except OSError as e: + raise DynamipsError("Can not list {}: {}".format(image_dir, str(e))) files.sort() images = [] for filename in files: @@ -724,7 +726,6 @@ class Dynamips(BaseManager): # read the first 7 bytes of the file. elf_header_start = f.read(7) except OSError as e: - print(e) continue # valid IOS images must start with the ELF magic number, be 32-bit, big endian and have an ELF version of 1 if elf_header_start == b'\x7fELF\x01\x02\x01':