1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-12 19:38:57 +00:00

Catch permission error when restoring a snapshot

Fix #899
This commit is contained in:
Julien Duponchelle 2017-02-13 15:30:02 +01:00
parent 5639cbe860
commit a576c57873
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

View File

@ -20,6 +20,7 @@ import os
import uuid
import shutil
import asyncio
import aiohttp.web
from datetime import datetime, timezone
@ -80,10 +81,13 @@ class Snapshot:
# We don't send close notif to clients because the close / open dance is purely internal
yield from self._project.close(ignore_notification=True)
self._project.controller.notification.emit("snapshot.restored", self.__json__())
if os.path.exists(os.path.join(self._project.path, "project-files")):
shutil.rmtree(os.path.join(self._project.path, "project-files"))
with open(self._path, "rb") as f:
project = yield from import_project(self._project.controller, self._project.id, f, location=self._project.path)
try:
if os.path.exists(os.path.join(self._project.path, "project-files")):
shutil.rmtree(os.path.join(self._project.path, "project-files"))
with open(self._path, "rb") as f:
project = yield from import_project(self._project.controller, self._project.id, f, location=self._project.path)
except (OSError, PermissionError) as e:
raise aiohttp.web.HTTPConflict(text=str(e))
yield from project.open()
return project