mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Make sure that the temporary image file is removed after uploading an image
This commit is contained in:
parent
cd096ac6e6
commit
89c67790ae
@ -335,13 +335,23 @@ async def write_image(
|
||||
if duplicate_image and os.path.dirname(duplicate_image.path) == os.path.dirname(image_path):
|
||||
raise InvalidImageError(f"Image {duplicate_image.filename} with "
|
||||
f"same checksum already exists in the same directory")
|
||||
except InvalidImageError:
|
||||
os.remove(tmp_path)
|
||||
raise
|
||||
os.chmod(tmp_path, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
|
||||
if not image_dir:
|
||||
directory = default_images_directory(image_type)
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
image_path = os.path.abspath(os.path.join(directory, image_filename))
|
||||
shutil.move(tmp_path, image_path)
|
||||
return await images_repo.add_image(image_name, image_type, image_size, image_path, checksum, checksum_algorithm="md5")
|
||||
os.chmod(image_path, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
|
||||
finally:
|
||||
try:
|
||||
os.remove(tmp_path)
|
||||
except OSError:
|
||||
log.warning(f"Could not remove '{tmp_path}'")
|
||||
|
||||
return await images_repo.add_image(
|
||||
image_name,
|
||||
image_type,
|
||||
image_size,
|
||||
image_path,
|
||||
checksum,
|
||||
checksum_algorithm="md5"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user