From f24fd42a69e75bc2f23f771a65997bab31d276ae Mon Sep 17 00:00:00 2001 From: Claus Date: Thu, 9 Feb 2017 13:36:56 +0100 Subject: [PATCH] GetFullPath now uses ShadowFileSystem. --- src/Umbraco.Core/IO/ShadowFileSystem.cs | 3 +++ src/Umbraco.Tests/IO/ShadowFileSystemTests.cs | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Umbraco.Core/IO/ShadowFileSystem.cs b/src/Umbraco.Core/IO/ShadowFileSystem.cs index ca1de0413c..faf3678495 100644 --- a/src/Umbraco.Core/IO/ShadowFileSystem.cs +++ b/src/Umbraco.Core/IO/ShadowFileSystem.cs @@ -245,6 +245,9 @@ namespace Umbraco.Core.IO public string GetFullPath(string path) { + ShadowNode sf; + if (Nodes.TryGetValue(NormPath(path), out sf)) + return sf.IsDir || sf.IsDelete ? null : _sfs.GetFullPath(path); return _fs.GetFullPath(path); } diff --git a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs index 112c93ecce..ca9b184892 100644 --- a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs @@ -655,5 +655,31 @@ namespace Umbraco.Tests.IO var sfsFiles = sfs.GetFiles(string.Empty).ToArray(); Assert.AreEqual(1, sfsFiles.Length); } + + [Test] + public void ShadowGetFullPath() + { + // Arrange + var path = IOHelper.MapPath("FileSysTests"); + Directory.CreateDirectory(path); + Directory.CreateDirectory(path + "/ShadowTests"); + Directory.CreateDirectory(path + "/ShadowSystem"); + + var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var ss = new ShadowFileSystem(fs, sfs); + + // Act + File.WriteAllText(path + "/ShadowTests/f1.txt", "foo"); + using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) + ss.AddFile("f2.txt", ms); + + // Assert + // ensure the files are located at the expected locations on the actual filesystem + var f1FullPath = ss.GetFullPath("f1.txt"); + var f2FullPath = ss.GetFullPath("f2.txt"); + Assert.AreEqual(Path.Combine(path, "ShadowTests", "f1.txt"), f1FullPath); + Assert.AreEqual(Path.Combine(path, "ShadowSystem", "f2.txt"), f2FullPath); + } } }