mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-17 17:24:51 +02:00
Fix issues when discovering images
This commit is contained in:
parent
466aaf5c13
commit
30f7c0ce74
@ -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(
|
||||
|
@ -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
|
||||
|
@ -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}'")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user