Skip to content

Commit

Permalink
Catch error when no space left on disk during export
Browse files Browse the repository at this point in the history
Fix #801
  • Loading branch information
julien-duponchelle committed Nov 28, 2016
1 parent 60a145a commit b3d83b1
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions gns3server/handlers/api/controller/project_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,22 +286,26 @@ def export_project(request, response):
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",
Expand Down

0 comments on commit b3d83b1

Please sign in to comment.