From e0071f5b599b9b538f5117dd1cf013132f76a961 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 10 Jan 2017 10:16:45 +0100 Subject: [PATCH] Catch error when a file is deleted during the compression of project Fix #860 --- gns3server/controller/project.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index dd599b3c..22f68867 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -696,13 +696,16 @@ class Project: if self._status == "closed": yield from self.open() - with tempfile.TemporaryDirectory() as tmpdir: - zipstream = yield from export_project(self, tmpdir, keep_compute_id=True, allow_all_nodes=True) - with open(os.path.join(tmpdir, "project.gns3p"), "wb+") as f: - for data in zipstream: - f.write(data) - with open(os.path.join(tmpdir, "project.gns3p"), "rb") as f: - project = yield from import_project(self._controller, str(uuid.uuid4()), f, location=location, name=name, keep_compute_id=True) + try: + with tempfile.TemporaryDirectory() as tmpdir: + zipstream = yield from export_project(self, tmpdir, keep_compute_id=True, allow_all_nodes=True) + with open(os.path.join(tmpdir, "project.gns3p"), "wb+") as f: + for data in zipstream: + f.write(data) + with open(os.path.join(tmpdir, "project.gns3p"), "rb") as f: + project = yield from import_project(self._controller, str(uuid.uuid4()), f, location=location, name=name, keep_compute_id=True) + except OSError as e: + raise aiohttp.web.HTTPConflict(text="Can not duplicate project: {}".format(str(e))) if previous_status == "closed": yield from self.close()