Fix thumbnails not being deleted from temp folder

This commit is contained in:
liszto
2025-12-06 03:29:54 +01:00
committed by GitHub
parent 997362fc97
commit 636908fc4d

View File

@@ -209,8 +209,11 @@ public class SkiaEncoder : IImageEncoder
return default;
}
using var codec = SKCodec.Create(safePath, out var result);
SKCodec? codec = null;
bool isSafePathTemp = !string.Equals(Path.GetFullPath(safePath), Path.GetFullPath(path), StringComparison.OrdinalIgnoreCase);
try
{
codec = SKCodec.Create(safePath, out var result);
switch (result)
{
case SKCodecResult.Success:
@@ -231,7 +234,6 @@ public class SkiaEncoder : IImageEncoder
default:
{
var boundsInfo = SKBitmap.DecodeBounds(safePath);
if (boundsInfo.Width > 0 && boundsInfo.Height > 0)
{
return new ImageDimensions(boundsInfo.Width, boundsInfo.Height);
@@ -241,10 +243,38 @@ public class SkiaEncoder : IImageEncoder
"Unable to determine image dimensions for {FilePath}: {SkCodecResult}",
path,
result);
return default;
}
}
}
finally
{
try
{
codec?.Dispose();
}
catch (Exception ex)
{
_logger.LogDebug(ex, "Error by closing codec for {FilePath}", safePath);
}
if (isSafePathTemp)
{
try
{
if (File.Exists(safePath))
{
File.Delete(safePath);
}
}
catch (Exception ex)
{
_logger.LogDebug(ex, "Unable to remove temporary file '{TempPath}'", safePath);
}
}
}
}
/// <inheritdoc />
/// <exception cref="ArgumentNullException">The path is null.</exception>