From 85ef421d728faaec177e0aca7f926948d192418e Mon Sep 17 00:00:00 2001 From: grossmj Date: Sat, 17 May 2014 18:39:37 -0600 Subject: [PATCH] Catch exceptions in file upload handler. --- gns3server/handlers/file_upload_handler.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gns3server/handlers/file_upload_handler.py b/gns3server/handlers/file_upload_handler.py index 41ac5682..d73f12d6 100644 --- a/gns3server/handlers/file_upload_handler.py +++ b/gns3server/handlers/file_upload_handler.py @@ -81,8 +81,12 @@ class FileUploadHandler(tornado.web.RequestHandler): if "file" in self.request.files: fileinfo = self.request.files["file"][0] destination_path = os.path.join(self._upload_dir, fileinfo['filename']) - with open(destination_path, 'wb') as f: - f.write(fileinfo['body']) + try: + with open(destination_path, 'wb') as f: + f.write(fileinfo['body']) + except OSError as e: + self.write("Could not upload {}: {}".format(fileinfo['filename'], e)) + return st = os.stat(destination_path) os.chmod(destination_path, st.st_mode | stat.S_IXUSR) self.redirect("/upload")