Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Jul 21, 2020
2 parents 57535bc + cc94e20 commit d7d4260
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 58 deletions.
4 changes: 2 additions & 2 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
30 changes: 19 additions & 11 deletions src/ImageProcessor.Web.Plugins.AzureBlobCache/AzureBlobCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AzureBlobCache>("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<AzureBlobCache>(sb.ToString());
return;
}
}

Expand Down
49 changes: 9 additions & 40 deletions src/ImageProcessor.Web/Caching/DiskCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,19 @@ public override Task TrimCacheAsync()
ImageProcessorBootstrapper.Instance.Logger.Log<DiskCache>($"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<DiskCache>($"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);
}
}

Expand Down Expand Up @@ -554,42 +558,6 @@ private static IEnumerable<string> SafeEnumerateDirectories(string directoryPath
return directories;
}

/// <summary>
/// Recursively delete the directories in the folder.
/// </summary>
/// <param name="directory">The current directory.</param>
/// <param name="root">The root path.</param>
/// <param name="token">The cancellation token.</param>
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<DiskCache>($"Unable to clean cached directory: {directory}, {ex.Message}");
}
}

/// <summary>
/// Sets the ETag Header
/// </summary>
Expand Down Expand Up @@ -621,7 +589,8 @@ private string GetETag()

return "\"" + hexFileTime + "\"";
}

return null;
}
}
}
}
4 changes: 2 additions & 2 deletions src/ImageProcessor.Web/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit d7d4260

Please sign in to comment.