Skip to content

Commit

Permalink
Attempt overwriting existing file, and catch and log failures
Browse files Browse the repository at this point in the history
  • Loading branch information
MellowArpeggiation committed Mar 8, 2018
1 parent af29ffd commit ada3e53
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ImageProcessor.Web/Caching/DiskCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,19 @@ public override async Task AddImageToCacheAsync(Stream stream, string contentTyp

// This is a hack. I don't know why there would ever be double access to the file but there is
// and it's causing errors to be thrown.
// Ensure that an attempt at overwrite is still made, so cached images can be updated
// https://github.com/JimBobSquarePants/ImageProcessor/issues/629
if (!File.Exists(this.CachedPath))
try
{
using (FileStream fileStream = File.Create(this.CachedPath, (int)stream.Length))
{
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
}
}
catch (Exception ex)
{
ImageProcessorBootstrapper.Instance.Logger.Log<DiskCache>($"Unable to write to file: {this.CachedPath}, {ex.Message}");
}
}

/// <summary>
Expand Down

0 comments on commit ada3e53

Please sign in to comment.