diff --git a/gns3server/api/routes/controller/images.py b/gns3server/api/routes/controller/images.py index 6bd3cc13..c23b04b9 100644 --- a/gns3server/api/routes/controller/images.py +++ b/gns3server/api/routes/controller/images.py @@ -129,7 +129,7 @@ async def get_image( async def delete_image( image_path: str, images_repo: ImagesRepository = Depends(get_repository(ImagesRepository)), -) -> None: +) -> Response: """ Delete an image. """ @@ -159,6 +159,8 @@ async def delete_image( if not success: raise ControllerError(f"Image '{image_path}' could not be deleted") + return Response(status_code=status.HTTP_204_NO_CONTENT) + @router.post("/prune", status_code=status.HTTP_204_NO_CONTENT) async def prune_images( diff --git a/gns3server/db/tasks.py b/gns3server/db/tasks.py index 99853993..f6ec4125 100644 --- a/gns3server/db/tasks.py +++ b/gns3server/db/tasks.py @@ -91,6 +91,8 @@ async def get_computes(app: FastAPI) -> List[dict]: def image_filter(change: Change, path: str) -> bool: if change == Change.added: + if path.endswith(".tmp") or path.endswith(".md5sum") or path.startswith("."): + return False header_magic_len = 7 with open(path, "rb") as f: image_header = f.read(header_magic_len) # read the first 7 bytes of the file diff --git a/gns3server/utils/images.py b/gns3server/utils/images.py index 816431fd..ff0986e5 100644 --- a/gns3server/utils/images.py +++ b/gns3server/utils/images.py @@ -139,7 +139,7 @@ async def discover_images(image_type: str, skip_image_paths: list = None) -> Lis for directory in images_directories(image_type): for root, _, filenames in os.walk(os.path.normpath(directory)): for filename in filenames: - if filename.endswith(".md5sum") or filename.startswith("."): + if filename.endswith(".tmp") or filename.endswith(".md5sum") or filename.startswith("."): continue path = os.path.join(root, filename) if not os.path.isfile(path) or skip_image_paths and path in skip_image_paths or path in files: @@ -343,7 +343,8 @@ async def write_image( os.chmod(image_path, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC) finally: try: - os.remove(tmp_path) + if os.path.exists(tmp_path): + os.remove(tmp_path) except OSError: log.warning(f"Could not remove '{tmp_path}'")