Skip to content

Commit 30f7330

Browse files
Move directory creation to constructor (to fix tests)
1 parent 3b2b9a0 commit 30f7330

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/ImageSharp.Web/Caching/PhysicalFileSystemCache.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public PhysicalFileSystemCache(
5353
this.cacheRootPath = GetCacheRoot(options.Value, environment.WebRootPath, environment.ContentRootPath);
5454
this.cacheFolderDepth = (int)options.Value.CacheFolderDepth;
5555
this.formatUtilities = formatUtilities;
56+
57+
// Ensure cache directory exists
58+
if (!Directory.Exists(this.cacheRootPath))
59+
{
60+
Directory.CreateDirectory(this.cacheRootPath);
61+
}
5662
}
5763

5864
/// <summary>
@@ -78,12 +84,6 @@ internal static string GetCacheRoot(PhysicalFileSystemCacheOptions cacheOptions,
7884

7985
string cacheFolderPath = Path.Combine(cacheRootPath, cacheOptions.CacheFolder);
8086

81-
// Ensure directory exists
82-
if (!Directory.Exists(cacheFolderPath))
83-
{
84-
Directory.CreateDirectory(cacheFolderPath);
85-
}
86-
8787
return PathUtils.EnsureTrailingSlash(cacheFolderPath);
8888
}
8989

src/ImageSharp.Web/Providers/PhysicalFileSystemProvider.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public PhysicalFileSystemProvider(
4747

4848
this.providerRootPath = GetProviderRoot(options.Value, environment.WebRootPath, environment.ContentRootPath);
4949
this.formatUtilities = formatUtilities;
50+
51+
// Ensure provider directory exists
52+
if (!Directory.Exists(this.providerRootPath))
53+
{
54+
Directory.CreateDirectory(this.providerRootPath);
55+
}
5056
}
5157

5258
/// <inheritdoc/>
@@ -99,12 +105,6 @@ internal static string GetProviderRoot(PhysicalFileSystemProviderOptions provide
99105
providerRootPath = Path.GetFullPath(providerRootPath, contentRootPath);
100106
}
101107

102-
// Ensure directory exists
103-
if (!Directory.Exists(providerRootPath))
104-
{
105-
Directory.CreateDirectory(providerRootPath);
106-
}
107-
108108
return PathUtils.EnsureTrailingSlash(providerRootPath);
109109
}
110110
}

0 commit comments

Comments
 (0)