Unwrap wrapped filesystems

This commit is contained in:
Stephan
2019-01-08 12:52:16 +01:00
parent cf631e60dd
commit 429423c07f
4 changed files with 41 additions and 1 deletions

View File

@@ -65,5 +65,33 @@ namespace Umbraco.Core.IO
}
fs.DeleteFile(tempFile);
}
/// <summary>
/// Unwraps a filesystem.
/// </summary>
/// <remarks>
/// <para>A filesystem can be wrapped in a <see cref="FileSystemWrapper"/> (public) or a <see cref="ShadowWrapper"/> (internal),
/// and this method deals with the various wrappers and </para>
/// </remarks>
public static IFileSystem Unwrap(this IFileSystem filesystem)
{
var unwrapping = true;
while (unwrapping)
{
switch (filesystem)
{
case FileSystemWrapper wrapper:
filesystem = wrapper.InnerFileSystem;
break;
case ShadowWrapper shadow:
filesystem = shadow.InnerFileSystem;
break;
default:
unwrapping = false;
break;
}
}
return filesystem;
}
}
}

View File

@@ -21,7 +21,7 @@ namespace Umbraco.Core.IO
InnerFileSystem = innerFileSystem;
}
public IFileSystem InnerFileSystem { get; internal set; }
internal IFileSystem InnerFileSystem { get; set; }
public IEnumerable<string> GetDirectories(string path)
{

View File

@@ -75,6 +75,8 @@ namespace Umbraco.Core.IO
}
}
public IFileSystem InnerFileSystem => _innerFileSystem;
private IFileSystem FileSystem
{
get

View File

@@ -86,6 +86,16 @@ namespace Umbraco.Tests.IO
Assert.AreSame(fileSystem1, fileSystem2);
}
[Test]
public void Can_Unwrap_MediaFileSystem()
{
var fileSystem = _factory.GetInstance<IMediaFileSystem>();
var unwrapped = fileSystem.Unwrap();
Assert.IsNotNull(unwrapped);
var physical = unwrapped as PhysicalFileSystem;
Assert.IsNotNull(physical);
}
[Test]
public void Can_Delete_MediaFiles()
{