Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Umbraco.Core/IO/PhysicalFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,11 @@ protected void WithRetry(Action action)
/// Creates a file provider.
/// </summary>
/// <returns>The file provider.</returns>
public IFileProvider Create() => new PhysicalFileProvider(_rootPath);
public IFileProvider Create()
{
Directory.CreateDirectory(_rootPath);
return new PhysicalFileProvider(_rootPath);
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See LICENSE for more details.

using System.Text;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
Expand Down Expand Up @@ -103,4 +104,32 @@ public void GetFullPathTest()
// that path is invalid as it would be outside the root directory
Assert.Throws<UnauthorizedAccessException>(() => _fileSystem.GetFullPath("../../foo.tmp"));
}

[Test]
public void CreateFileProviderCreatesDirectoryIfMissing()
{
var nonExistentPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests", "NonExistent");
if (Directory.Exists(nonExistentPath))
{
Directory.Delete(nonExistentPath, true);
}

var fs = new PhysicalFileSystem(
TestHelper.IOHelper,
TestHelper.GetHostingEnvironment(),
Mock.Of<ILogger<PhysicalFileSystem>>(),
nonExistentPath,
"/Media/");

IFileProvider fileProvider = ((IFileProviderFactory)fs).Create();
try
{
Assert.IsNotNull(fileProvider);
Assert.IsTrue(Directory.Exists(nonExistentPath));
}
finally
{
(fileProvider as IDisposable)?.Dispose();
}
}
}
Loading