Skip to content

Commit

Permalink
Catch error when a file is deleted during the compression of project
Browse files Browse the repository at this point in the history
Fix #860
  • Loading branch information
julien-duponchelle committed Jan 10, 2017
1 parent 6664612 commit e0071f5
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions gns3server/controller/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,16 @@ def duplicate(self, name=None, location=None):
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()
Expand Down

0 comments on commit e0071f5

Please sign in to comment.