diff --git a/build/build.ps1 b/build/build.ps1 index 14e886689..704e14555 100644 --- a/build/build.ps1 +++ b/build/build.ps1 @@ -35,7 +35,7 @@ $imageProcessorPluginsWebP = @{ $imageprocessorWeb = @{ name = "ImageProcessor.Web" - version = "4.12.0" + version = "4.12.1" folder = Join-Path $buildPath "src\ImageProcessor.Web" output = Join-Path $binPath "ImageProcessor.Web\lib\net452" csproj = "ImageProcessor.Web.csproj" @@ -49,7 +49,7 @@ $imageprocessorWebConfig = @{ $imageProcessorWebPluginsAzureBlobCache = @{ name = "ImageProcessor.Web.Plugins.AzureBlobCache" - version = "1.7.0" + version = "1.7.1" folder = Join-Path $buildPath "src\ImageProcessor.Web.Plugins.AzureBlobCache" output = Join-Path $binPath "ImageProcessor.Web.Plugins.AzureBlobCache\lib\net452" csproj = "ImageProcessor.Web.Plugins.AzureBlobCache.csproj" diff --git a/src/ImageProcessor.Web.Plugins.AmazonS3Cache/Properties/AssemblyInfo.cs b/src/ImageProcessor.Web.Plugins.AmazonS3Cache/Properties/AssemblyInfo.cs index 327867e5e..7636589cf 100644 --- a/src/ImageProcessor.Web.Plugins.AmazonS3Cache/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor.Web.Plugins.AmazonS3Cache/Properties/AssemblyInfo.cs @@ -39,6 +39,6 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("1.7.0.00000")] -[assembly: AssemblyVersion("1.7.0.00000")] -[assembly: AssemblyFileVersion("1.7.0.00000")] +// [assembly: AssemblyVersion("1.2.0.00000")] +[assembly: AssemblyVersion("1.2.0.00000")] +[assembly: AssemblyFileVersion("1.2.0.00000")] diff --git a/src/ImageProcessor.Web.Plugins.AzureBlobCache/AzureBlobCache.cs b/src/ImageProcessor.Web.Plugins.AzureBlobCache/AzureBlobCache.cs index d3c3b6587..a880aaa40 100644 --- a/src/ImageProcessor.Web.Plugins.AzureBlobCache/AzureBlobCache.cs +++ b/src/ImageProcessor.Web.Plugins.AzureBlobCache/AzureBlobCache.cs @@ -16,6 +16,7 @@ namespace ImageProcessor.Web.Plugins.AzureBlobCache using System.IO; using System.Linq; using System.Net; + using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; @@ -357,18 +358,25 @@ public override void RewritePath(HttpContext context) catch (StorageException ex) { // A 304 is not a true error, we still need to feed back. - var webException = ex.InnerException as WebException; - if (!(webException is null)) + if (ex.RequestInformation?.HttpStatusCode == (int)HttpStatusCode.NotModified) { - if (webException.Response != null && (((HttpWebResponse)webException.Response).StatusCode == HttpStatusCode.NotModified)) - { - is304 = true; - } - else - { - ImageProcessorBootstrapper.Instance.Logger.Log("Unable to stream cached path: " + this.cachedRewritePath); - return; - } + is304 = true; + } + else if (ex.InnerException is WebException webException + && webException.Response is HttpWebResponse httpWebResponse + && httpWebResponse.StatusCode == HttpStatusCode.NotModified) + { + is304 = true; + } + else + { + var sb = new StringBuilder(); + sb.AppendFormat("Unable to stream cached path: {0}", this.cachedRewritePath); + sb.AppendLine(); + sb.AppendFormat("Exception: {0}", ex.ToString()); + + ImageProcessorBootstrapper.Instance.Logger.Log(sb.ToString()); + return; } } diff --git a/src/ImageProcessor.Web/Caching/DiskCache.cs b/src/ImageProcessor.Web/Caching/DiskCache.cs index fb201ace9..e9d390377 100644 --- a/src/ImageProcessor.Web/Caching/DiskCache.cs +++ b/src/ImageProcessor.Web/Caching/DiskCache.cs @@ -255,15 +255,19 @@ public override Task TrimCacheAsync() ImageProcessorBootstrapper.Instance.Logger.Log($"Unable to clean cached file: {fileInfo.FullName}, {ex.Message}"); } } + + // If the directory is empty, delete it to remove the FCN + if (count == 0 + && Directory.GetDirectories(directory, "*", SearchOption.TopDirectoryOnly).Length == 0) + { + Directory.Delete(directory); + } } catch (Exception ex) { // Log it but skip to the next directory ImageProcessorBootstrapper.Instance.Logger.Log($"Unable to clean cached directory: {directory}, {ex.Message}"); } - - // If the directory is empty of files delete it to remove the FCN - this.RecursivelyDeleteEmptyDirectories(directory, validatedAbsoluteCachePath, token); } } @@ -554,42 +558,6 @@ private static IEnumerable SafeEnumerateDirectories(string directoryPath return directories; } - /// - /// Recursively delete the directories in the folder. - /// - /// The current directory. - /// The root path. - /// The cancellation token. - private void RecursivelyDeleteEmptyDirectories(string directory, string root, CancellationToken token) - { - if (token.IsCancellationRequested) - { - return; - } - - try - { - if (directory == root) - { - return; - } - - // If the directory is empty of files delete it to remove the FCN. - if (Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly).Length == 0 - && Directory.GetDirectories(directory, "*", SearchOption.TopDirectoryOnly).Length == 0) - { - Directory.Delete(directory); - } - - this.RecursivelyDeleteEmptyDirectories(Directory.GetParent(directory).FullName, root, token); - } - catch (Exception ex) - { - // Log it but skip to the next directory. - ImageProcessorBootstrapper.Instance.Logger.Log($"Unable to clean cached directory: {directory}, {ex.Message}"); - } - } - /// /// Sets the ETag Header /// @@ -621,7 +589,8 @@ private string GetETag() return "\"" + hexFileTime + "\""; } + return null; } } -} \ No newline at end of file +} diff --git a/src/ImageProcessor.Web/Properties/AssemblyInfo.cs b/src/ImageProcessor.Web/Properties/AssemblyInfo.cs index 5f3bd5a65..eb9552f67 100644 --- a/src/ImageProcessor.Web/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor.Web/Properties/AssemblyInfo.cs @@ -41,7 +41,7 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("4.12.0.00000")] -[assembly: AssemblyFileVersion("4.12.0.00000")] +[assembly: AssemblyVersion("4.12.1.00000")] +[assembly: AssemblyFileVersion("4.12.1.00000")] [assembly: InternalsVisibleTo("ImageProcessor.Web.UnitTests")]