Catch error when no space left on disk during export

Fix #801
pull/807/head
Julien Duponchelle 8 years ago
parent 60a145afbb
commit b3d83b1b0b
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

@ -286,22 +286,26 @@ class ProjectHandler:
controller = Controller.instance()
project = yield from controller.get_loaded_project(request.match_info["project_id"])
with tempfile.TemporaryDirectory() as tmp_dir:
datas = yield from export_project(project, tmp_dir, include_images=bool(request.get("include_images", "0")))
# We need to do that now because export could failed and raise an HTTP error
# that why response start need to be the later possible
response.content_type = 'application/gns3project'
response.headers['CONTENT-DISPOSITION'] = 'attachment; filename="{}.gns3project"'.format(project.name)
response.enable_chunked_encoding()
# Very important: do not send a content length otherwise QT closes the connection (curl can consume the feed)
response.content_length = None
response.start(request)
for data in datas:
response.write(data)
yield from response.drain()
try:
with tempfile.TemporaryDirectory() as tmp_dir:
datas = yield from export_project(project, tmp_dir, include_images=bool(request.get("include_images", "0")))
# We need to do that now because export could failed and raise an HTTP error
# that why response start need to be the later possible
response.content_type = 'application/gns3project'
response.headers['CONTENT-DISPOSITION'] = 'attachment; filename="{}.gns3project"'.format(project.name)
response.enable_chunked_encoding()
# Very important: do not send a content length otherwise QT closes the connection (curl can consume the feed)
response.content_length = None
response.start(request)
yield from response.write_eof()
for data in datas:
response.write(data)
yield from response.drain()
yield from response.write_eof()
# Will be raise if you have no space left or permission issue on your temporary directory
except OSError as e:
raise aiohttp.web.HTTPNotFound(text="Can't export project: {}".format(str(e)))
@Route.post(
r"/projects/{project_id}/import",

Loading…
Cancel
Save