mirror of
https://github.com/GNS3/gns3-server
synced 2025-04-20 01:29:01 +00:00
Allow an image to be uploaded to the controller again even if it is already in the database
This commit is contained in:
parent
0826b9c259
commit
aa8ccf4f82
@ -148,11 +148,6 @@ async def upload_image(
|
||||
if os.path.commonprefix([base_images_directory, full_path]) != base_images_directory:
|
||||
raise ControllerForbiddenError(f"Cannot write image, '{image_path}' is forbidden")
|
||||
|
||||
image = await images_repo.get_image(image_path)
|
||||
if image:
|
||||
log.warning(f"Image '{image_path}' already exists")
|
||||
return image
|
||||
|
||||
try:
|
||||
allow_raw_image = Config.instance().settings.Server.allow_raw_images
|
||||
image = await write_image(image_path, full_path, request.stream(), images_repo, allow_raw_image=allow_raw_image)
|
||||
|
@ -342,6 +342,12 @@ async def write_image(
|
||||
allow_raw_image=False
|
||||
) -> models.Image:
|
||||
|
||||
db_image = await images_repo.get_image(image_path)
|
||||
if db_image and os.path.exists(image_path):
|
||||
# the image already exists in the database and on disk
|
||||
log.info(f"Image {image_path} already exists")
|
||||
return db_image
|
||||
|
||||
image_dir, image_name = os.path.split(image_filename)
|
||||
log.info(f"Writing image file to '{image_path}'")
|
||||
# Store the file under its final name only when the upload is completed
|
||||
@ -381,6 +387,10 @@ async def write_image(
|
||||
except OSError:
|
||||
log.warning(f"Could not remove '{tmp_path}'")
|
||||
|
||||
if db_image:
|
||||
# the image already exists in the database, no need to add it again
|
||||
return db_image
|
||||
|
||||
return await images_repo.add_image(
|
||||
image_name,
|
||||
image_type,
|
||||
|
Loading…
Reference in New Issue
Block a user