77using Microsoft . AspNetCore . Hosting ;
88using Microsoft . AspNetCore . Http ;
99using Microsoft . AspNetCore . Http . Extensions ;
10- using Microsoft . Extensions . FileProviders ;
1110using Microsoft . Extensions . Options ;
1211using SixLabors . ImageSharp . Web . Resolvers ;
1312
@@ -19,9 +18,9 @@ namespace SixLabors.ImageSharp.Web.Providers
1918 public class PhysicalFileSystemProvider : IImageProvider
2019 {
2120 /// <summary>
22- /// The file provider abstraction .
21+ /// The root path for the provider .
2322 /// </summary>
24- private readonly IFileProvider fileProvider ;
23+ private readonly string providerRootPath ;
2524
2625 /// <summary>
2726 /// Contains various format helper methods based on the current configuration.
@@ -44,18 +43,12 @@ public PhysicalFileSystemProvider(
4443 FormatUtilities formatUtilities )
4544 {
4645 Guard . NotNull ( environment , nameof ( environment ) ) ;
47-
48- // ContentRootPath is never null.
49- // https://github.com/dotnet/aspnetcore/blob/b89eba6c3cda331ee98063e3c4a04267ec540315/src/Hosting/Hosting/src/WebHostBuilder.cs#L262
5046 Guard . NotNullOrWhiteSpace ( environment . WebRootPath , nameof ( environment . WebRootPath ) ) ;
5147
5248 // Allow configuration of the provider without having to register everything
5349 PhysicalFileSystemProviderOptions providerOptions = options != null ? options . Value : new ( ) ;
54- string providerRootPath = GetProviderRoot ( providerOptions , environment . WebRootPath , environment . ContentRootPath ) ;
50+ this . providerRootPath = GetProviderRoot ( providerOptions , environment . WebRootPath , environment . ContentRootPath ) ;
5551
56- // Ensure provider directory is created before initializing the file provider
57- Directory . CreateDirectory ( providerRootPath ) ;
58- this . fileProvider = new PhysicalFileProvider ( providerRootPath ) ;
5952 this . formatUtilities = formatUtilities ;
6053 }
6154
@@ -72,16 +65,16 @@ public bool IsValidRequest(HttpContext context)
7265 /// <inheritdoc/>
7366 public Task < IImageResolver > GetAsync ( HttpContext context )
7467 {
75- // Path has already been correctly parsed before here.
76- IFileInfo fileInfo = this . fileProvider . GetFileInfo ( context . Request . Path . Value ) ;
68+ string path = Path . Join ( this . providerRootPath , context . Request . Path . Value ) ;
7769
78- // Check to see if the file exists.
70+ // Check to see if the file exists
71+ var fileInfo = new FileInfo ( path ) ;
7972 if ( ! fileInfo . Exists )
8073 {
8174 return Task . FromResult < IImageResolver > ( null ) ;
8275 }
8376
84- var metadata = new ImageMetadata ( fileInfo . LastModified . UtcDateTime , fileInfo . Length ) ;
77+ var metadata = new ImageMetadata ( fileInfo . LastWriteTimeUtc , fileInfo . Length ) ;
8578 return Task . FromResult < IImageResolver > ( new PhysicalFileSystemResolver ( fileInfo , metadata ) ) ;
8679 }
8780
0 commit comments