1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 09:18:08 +00:00

Catch exceptions in file upload handler.

This commit is contained in:
grossmj 2014-05-17 18:39:37 -06:00
parent f4ab8e2dd0
commit 85ef421d72

View File

@ -81,8 +81,12 @@ class FileUploadHandler(tornado.web.RequestHandler):
if "file" in self.request.files: if "file" in self.request.files:
fileinfo = self.request.files["file"][0] fileinfo = self.request.files["file"][0]
destination_path = os.path.join(self._upload_dir, fileinfo['filename']) destination_path = os.path.join(self._upload_dir, fileinfo['filename'])
with open(destination_path, 'wb') as f: try:
f.write(fileinfo['body']) 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) st = os.stat(destination_path)
os.chmod(destination_path, st.st_mode | stat.S_IXUSR) os.chmod(destination_path, st.st_mode | stat.S_IXUSR)
self.redirect("/upload") self.redirect("/upload")