1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Fix topology images (Pictures) disappearing from projects. Fixes #1514.

This commit is contained in:
grossmj 2019-02-21 23:58:54 +07:00
parent 1ef1872f8e
commit a13d063aa1
2 changed files with 14 additions and 12 deletions

View File

@ -55,7 +55,7 @@ class Drawing:
return self._id return self._id
@property @property
def ressource_filename(self): def resource_filename(self):
""" """
If the svg content has been dump to an external file return is name otherwise None If the svg content has been dump to an external file return is name otherwise None
""" """

View File

@ -146,7 +146,6 @@ class Project:
} }
) )
def reset(self): def reset(self):
""" """
Called when open/close a project. Cleanup internal stuff Called when open/close a project. Cleanup internal stuff
@ -704,24 +703,26 @@ class Project:
# We don't care if a compute is down at this step # We don't care if a compute is down at this step
except (ComputeError, aiohttp.web.HTTPError, aiohttp.ClientResponseError, TimeoutError): except (ComputeError, aiohttp.web.HTTPError, aiohttp.ClientResponseError, TimeoutError):
pass pass
self._cleanPictures() self._clean_pictures()
self._status = "closed" self._status = "closed"
if not ignore_notification: if not ignore_notification:
self.controller.notification.emit("project.closed", self.__json__()) self.controller.notification.emit("project.closed", self.__json__())
def _cleanPictures(self): def _clean_pictures(self):
""" """
Delete unused images Delete unused pictures.
""" """
# Project have been deleted # Project have been deleted or is loading or is not opened
if not os.path.exists(self.path): if not os.path.exists(self.path) or self._loading or self._status != "opened":
return return
try: try:
pictures = set(os.listdir(self.pictures_directory)) pictures = set(os.listdir(self.pictures_directory))
for drawing in self._drawings.values(): for drawing in self._drawings.values():
try: try:
pictures.remove(drawing.ressource_filename) resource_filename = drawing.resource_filename
if resource_filename:
pictures.remove(resource_filename)
except KeyError: except KeyError:
pass pass
@ -733,11 +734,12 @@ class Project:
except KeyError: except KeyError:
pass pass
for pic_filename in pictures:
for pict in pictures: path = os.path.join(self.pictures_directory, pic_filename)
os.remove(os.path.join(self.pictures_directory, pict)) log.info("Deleting unused picture '{}'".format(path))
os.remove(path)
except OSError as e: except OSError as e:
log.warning(str(e)) log.warning("Could not delete unused pictures: {}".format(e))
@asyncio.coroutine @asyncio.coroutine
def delete(self): def delete(self):