Fix issues when discovering images

This commit is contained in:
grossmj 2022-06-03 15:35:33 +07:00
parent 466aaf5c13
commit 30f7c0ce74
3 changed files with 8 additions and 3 deletions

View File

@ -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(

View File

@ -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

View 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,6 +343,7 @@ async def write_image(
os.chmod(image_path, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
finally:
try:
if os.path.exists(tmp_path):
os.remove(tmp_path)
except OSError:
log.warning(f"Could not remove '{tmp_path}'")