From ce9e0047cc006a0b57db42acf524e15bdd369152 Mon Sep 17 00:00:00 2001 From: hexawyz <8518235+hexawyz@users.noreply.github.com> Date: Sat, 8 Feb 2025 23:36:59 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Do=20not=20overwrite=20cac?= =?UTF-8?q?hed=20image=20files.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Exo/Service/Exo.Service.Core/ImageStorageService.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Exo/Service/Exo.Service.Core/ImageStorageService.cs b/src/Exo/Service/Exo.Service.Core/ImageStorageService.cs index 73d7899..21b73f5 100644 --- a/src/Exo/Service/Exo.Service.Core/ImageStorageService.cs +++ b/src/Exo/Service/Exo.Service.Core/ImageStorageService.cs @@ -433,7 +433,11 @@ bool shouldApplyCircularMask TransformImage(stream, image, sourceRectangle, targetFormat, targetSize, shouldStripAnimations, shouldApplyCircularMask); var physicalImageId = XxHash128.HashToUInt128(stream.GetBuffer().AsSpan(0, (int)stream.Length), PhysicalImageIdHashSeed); string fileName = GetFileName(_imageCacheDirectory, physicalImageId); - File.WriteAllBytes(fileName, stream.GetBuffer().AsSpan(0, (int)stream.Length)); + // Assume that if a file exists, it is already correct. We want to avoid wearing the disk if we don't need to. + if (!File.Exists(fileName)) + { + File.WriteAllBytes(fileName, stream.GetBuffer().AsSpan(0, (int)stream.Length)); + } return (physicalImageId, targetFormat, GetImageFile(physicalImageId)); } }