From 4f204543e6ad1af4d9c9ef5e730a8667bcbcfc70 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 19 Nov 2019 07:52:40 +0100 Subject: [PATCH] AB3734 - Moved alot of stuff from Umbraco.Core.IO into abstractions --- .../Composing/TargetedServiceFactory.cs | 0 .../GuidUtils.cs | 0 .../IO/FileSecurityException.cs | 0 .../IO/FileSystemExtensions.cs | 2 +- .../IO/FileSystemWrapper.cs | 0 .../IO/FileSystems.cs | 28 +++--- .../IO/IMediaFileSystem.cs | 0 .../IO/IMediaPathScheme.cs | 0 .../IO/MediaFileSystem.cs | 8 +- .../CombinedGuidsMediaPathScheme.cs | 0 .../OriginalMediaPathScheme.cs | 0 .../TwoGuidsMediaPathScheme.cs | 0 .../MediaPathSchemes/UniqueMediaPathScheme.cs | 0 .../IO/PhysicalFileSystem.cs | 41 +++++---- .../IO/ShadowFileSystem.cs | 0 .../IO/ShadowFileSystems.cs | 0 .../IO/ShadowWrapper.cs | 17 ++-- .../IO/SupportingFileSystems.cs | 0 .../IO/SystemFiles.cs | 1 - .../IO/ViewHelper.cs | 0 .../Umbraco.Abstractions.csproj | 9 ++ .../CompositionExtensions/FileSystems.cs | 3 +- src/Umbraco.Core/IO/SystemDirectories.cs | 12 --- src/Umbraco.Core/Umbraco.Core.csproj | 21 ----- .../IO/PhysicalFileSystemTests.cs | 3 +- src/Umbraco.Tests/IO/ShadowFileSystemTests.cs | 86 +++++++++---------- src/Umbraco.Tests/Models/MediaXmlTest.cs | 3 +- .../PartialViewRepositoryTests.cs | 2 +- .../Repositories/ScriptRepositoryTest.cs | 2 +- .../Repositories/StylesheetRepositoryTest.cs | 2 +- .../Repositories/TemplateRepositoryTest.cs | 4 +- .../PropertyEditors/ImageCropperTest.cs | 3 +- .../Scoping/ScopeFileSystemsTests.cs | 4 +- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 3 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 3 +- .../Editors/BackOfficeAssetsController.cs | 12 ++- src/Umbraco.Web/Trees/FilesTreeController.cs | 12 ++- 37 files changed, 148 insertions(+), 133 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Composing/TargetedServiceFactory.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/GuidUtils.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/FileSecurityException.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/FileSystemExtensions.cs (97%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/FileSystemWrapper.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/FileSystems.cs (91%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/IMediaFileSystem.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/IMediaPathScheme.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/MediaFileSystem.cs (94%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/MediaPathSchemes/CombinedGuidsMediaPathScheme.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/MediaPathSchemes/OriginalMediaPathScheme.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/MediaPathSchemes/TwoGuidsMediaPathScheme.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/MediaPathSchemes/UniqueMediaPathScheme.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/PhysicalFileSystem.cs (90%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/ShadowFileSystem.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/ShadowFileSystems.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/ShadowWrapper.cs (89%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/SupportingFileSystems.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/SystemFiles.cs (94%) rename src/{Umbraco.Core => Umbraco.Abstractions}/IO/ViewHelper.cs (100%) delete mode 100644 src/Umbraco.Core/IO/SystemDirectories.cs diff --git a/src/Umbraco.Core/Composing/TargetedServiceFactory.cs b/src/Umbraco.Abstractions/Composing/TargetedServiceFactory.cs similarity index 100% rename from src/Umbraco.Core/Composing/TargetedServiceFactory.cs rename to src/Umbraco.Abstractions/Composing/TargetedServiceFactory.cs diff --git a/src/Umbraco.Core/GuidUtils.cs b/src/Umbraco.Abstractions/GuidUtils.cs similarity index 100% rename from src/Umbraco.Core/GuidUtils.cs rename to src/Umbraco.Abstractions/GuidUtils.cs diff --git a/src/Umbraco.Core/IO/FileSecurityException.cs b/src/Umbraco.Abstractions/IO/FileSecurityException.cs similarity index 100% rename from src/Umbraco.Core/IO/FileSecurityException.cs rename to src/Umbraco.Abstractions/IO/FileSecurityException.cs diff --git a/src/Umbraco.Core/IO/FileSystemExtensions.cs b/src/Umbraco.Abstractions/IO/FileSystemExtensions.cs similarity index 97% rename from src/Umbraco.Core/IO/FileSystemExtensions.cs rename to src/Umbraco.Abstractions/IO/FileSystemExtensions.cs index e0f5af75c5..444f312153 100644 --- a/src/Umbraco.Core/IO/FileSystemExtensions.cs +++ b/src/Umbraco.Abstractions/IO/FileSystemExtensions.cs @@ -55,7 +55,7 @@ namespace Umbraco.Core.IO } // TODO: Currently this is the only way to do this - internal static void CreateFolder(this IFileSystem fs, string folderPath) + public static void CreateFolder(this IFileSystem fs, string folderPath) { var path = fs.GetRelativePath(folderPath); var tempFile = Path.Combine(path, Guid.NewGuid().ToString("N") + ".tmp"); diff --git a/src/Umbraco.Core/IO/FileSystemWrapper.cs b/src/Umbraco.Abstractions/IO/FileSystemWrapper.cs similarity index 100% rename from src/Umbraco.Core/IO/FileSystemWrapper.cs rename to src/Umbraco.Abstractions/IO/FileSystemWrapper.cs diff --git a/src/Umbraco.Core/IO/FileSystems.cs b/src/Umbraco.Abstractions/IO/FileSystems.cs similarity index 91% rename from src/Umbraco.Core/IO/FileSystems.cs rename to src/Umbraco.Abstractions/IO/FileSystems.cs index 08f56b5869..2416883c64 100644 --- a/src/Umbraco.Core/IO/FileSystems.cs +++ b/src/Umbraco.Abstractions/IO/FileSystems.cs @@ -59,7 +59,7 @@ namespace Umbraco.Core.IO } // set by the scope provider when taking control of filesystems - internal Func IsScoped { get; set; } = () => false; + public Func IsScoped { get; set; } = () => false; #endregion @@ -124,17 +124,17 @@ namespace Umbraco.Core.IO // but it does not really matter what we return - here, null private object CreateWellKnownFileSystems() { - var macroPartialFileSystem = new PhysicalFileSystem(Constants.SystemDirectories.MacroPartials); - var partialViewsFileSystem = new PhysicalFileSystem(Constants.SystemDirectories.PartialViews); - var stylesheetsFileSystem = new PhysicalFileSystem(_globalSettings.UmbracoCssPath); - var scriptsFileSystem = new PhysicalFileSystem(_globalSettings.UmbracoScriptsPath); - var mvcViewsFileSystem = new PhysicalFileSystem(Constants.SystemDirectories.MvcViews); + var macroPartialFileSystem = new PhysicalFileSystem(_ioHelper, _logger, Constants.SystemDirectories.MacroPartials); + var partialViewsFileSystem = new PhysicalFileSystem(_ioHelper, _logger, Constants.SystemDirectories.PartialViews); + var stylesheetsFileSystem = new PhysicalFileSystem(_ioHelper, _logger, _globalSettings.UmbracoCssPath); + var scriptsFileSystem = new PhysicalFileSystem(_ioHelper, _logger, _globalSettings.UmbracoScriptsPath); + var mvcViewsFileSystem = new PhysicalFileSystem(_ioHelper, _logger, Constants.SystemDirectories.MvcViews); - _macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, "macro-partials", IsScoped); - _partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, "partials", IsScoped); - _stylesheetsFileSystem = new ShadowWrapper(stylesheetsFileSystem, "css", IsScoped); - _scriptsFileSystem = new ShadowWrapper(scriptsFileSystem, "scripts", IsScoped); - _mvcViewsFileSystem = new ShadowWrapper(mvcViewsFileSystem, "views", IsScoped); + _macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, _ioHelper, _logger,"macro-partials", IsScoped); + _partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, _ioHelper, _logger,"partials", IsScoped); + _stylesheetsFileSystem = new ShadowWrapper(stylesheetsFileSystem, _ioHelper, _logger,"css", IsScoped); + _scriptsFileSystem = new ShadowWrapper(scriptsFileSystem, _ioHelper, _logger,"scripts", IsScoped); + _mvcViewsFileSystem = new ShadowWrapper(mvcViewsFileSystem, _ioHelper, _logger,"views", IsScoped); // TODO: do we need a lock here? _shadowWrappers.Add(_macroPartialFileSystem); @@ -212,11 +212,11 @@ namespace Umbraco.Core.IO // global shadow for the entire application, so great care should be taken to ensure that the // application is *not* doing anything else when using a shadow. - internal ICompletable Shadow() + public ICompletable Shadow() { if (Volatile.Read(ref _wkfsInitialized) == false) EnsureWellKnownFileSystems(); - var id = ShadowWrapper.CreateShadowId(); + var id = ShadowWrapper.CreateShadowId(_ioHelper); return new ShadowFileSystems(this, id); // will invoke BeginShadow and EndShadow } @@ -274,7 +274,7 @@ namespace Umbraco.Core.IO { lock (_shadowLocker) { - var wrapper = new ShadowWrapper(filesystem, shadowPath, IsScoped); + var wrapper = new ShadowWrapper(filesystem, _ioHelper, _logger, shadowPath, IsScoped); if (_shadowCurrentId != null) wrapper.Shadow(_shadowCurrentId); _shadowWrappers.Add(wrapper); diff --git a/src/Umbraco.Core/IO/IMediaFileSystem.cs b/src/Umbraco.Abstractions/IO/IMediaFileSystem.cs similarity index 100% rename from src/Umbraco.Core/IO/IMediaFileSystem.cs rename to src/Umbraco.Abstractions/IO/IMediaFileSystem.cs diff --git a/src/Umbraco.Core/IO/IMediaPathScheme.cs b/src/Umbraco.Abstractions/IO/IMediaPathScheme.cs similarity index 100% rename from src/Umbraco.Core/IO/IMediaPathScheme.cs rename to src/Umbraco.Abstractions/IO/IMediaPathScheme.cs diff --git a/src/Umbraco.Core/IO/MediaFileSystem.cs b/src/Umbraco.Abstractions/IO/MediaFileSystem.cs similarity index 94% rename from src/Umbraco.Core/IO/MediaFileSystem.cs rename to src/Umbraco.Abstractions/IO/MediaFileSystem.cs index edcbfadf0d..d2d04204a1 100644 --- a/src/Umbraco.Core/IO/MediaFileSystem.cs +++ b/src/Umbraco.Abstractions/IO/MediaFileSystem.cs @@ -22,16 +22,18 @@ namespace Umbraco.Core.IO private readonly IMediaPathScheme _mediaPathScheme; private readonly IContentSection _contentConfig; private readonly ILogger _logger; + private readonly IIOHelper _ioHelper; /// /// Initializes a new instance of the class. /// - public MediaFileSystem(IFileSystem innerFileSystem, IContentSection contentConfig, IMediaPathScheme mediaPathScheme, ILogger logger) + public MediaFileSystem(IFileSystem innerFileSystem, IContentSection contentConfig, IMediaPathScheme mediaPathScheme, ILogger logger, IIOHelper ioHelper) : base(innerFileSystem) { _contentConfig = contentConfig; _mediaPathScheme = mediaPathScheme; _logger = logger; + _ioHelper = ioHelper; } /// @@ -68,7 +70,7 @@ namespace Umbraco.Core.IO { filename = Path.GetFileName(filename); if (filename == null) throw new ArgumentException("Cannot become a safe filename.", nameof(filename)); - filename = Current.IOHelper.SafeFileName(filename.ToLowerInvariant()); + filename = _ioHelper.SafeFileName(filename.ToLowerInvariant()); return _mediaPathScheme.GetFilePath(this, cuid, puid, filename); } @@ -78,7 +80,7 @@ namespace Umbraco.Core.IO { filename = Path.GetFileName(filename); if (filename == null) throw new ArgumentException("Cannot become a safe filename.", nameof(filename)); - filename = Current.IOHelper.SafeFileName(filename.ToLowerInvariant()); + filename = _ioHelper.SafeFileName(filename.ToLowerInvariant()); return _mediaPathScheme.GetFilePath(this, cuid, puid, filename, prevpath); } diff --git a/src/Umbraco.Core/IO/MediaPathSchemes/CombinedGuidsMediaPathScheme.cs b/src/Umbraco.Abstractions/IO/MediaPathSchemes/CombinedGuidsMediaPathScheme.cs similarity index 100% rename from src/Umbraco.Core/IO/MediaPathSchemes/CombinedGuidsMediaPathScheme.cs rename to src/Umbraco.Abstractions/IO/MediaPathSchemes/CombinedGuidsMediaPathScheme.cs diff --git a/src/Umbraco.Core/IO/MediaPathSchemes/OriginalMediaPathScheme.cs b/src/Umbraco.Abstractions/IO/MediaPathSchemes/OriginalMediaPathScheme.cs similarity index 100% rename from src/Umbraco.Core/IO/MediaPathSchemes/OriginalMediaPathScheme.cs rename to src/Umbraco.Abstractions/IO/MediaPathSchemes/OriginalMediaPathScheme.cs diff --git a/src/Umbraco.Core/IO/MediaPathSchemes/TwoGuidsMediaPathScheme.cs b/src/Umbraco.Abstractions/IO/MediaPathSchemes/TwoGuidsMediaPathScheme.cs similarity index 100% rename from src/Umbraco.Core/IO/MediaPathSchemes/TwoGuidsMediaPathScheme.cs rename to src/Umbraco.Abstractions/IO/MediaPathSchemes/TwoGuidsMediaPathScheme.cs diff --git a/src/Umbraco.Core/IO/MediaPathSchemes/UniqueMediaPathScheme.cs b/src/Umbraco.Abstractions/IO/MediaPathSchemes/UniqueMediaPathScheme.cs similarity index 100% rename from src/Umbraco.Core/IO/MediaPathSchemes/UniqueMediaPathScheme.cs rename to src/Umbraco.Abstractions/IO/MediaPathSchemes/UniqueMediaPathScheme.cs diff --git a/src/Umbraco.Core/IO/PhysicalFileSystem.cs b/src/Umbraco.Abstractions/IO/PhysicalFileSystem.cs similarity index 90% rename from src/Umbraco.Core/IO/PhysicalFileSystem.cs rename to src/Umbraco.Abstractions/IO/PhysicalFileSystem.cs index 2e133a03c3..01b58ec3cd 100644 --- a/src/Umbraco.Core/IO/PhysicalFileSystem.cs +++ b/src/Umbraco.Abstractions/IO/PhysicalFileSystem.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using Umbraco.Core.Composing; using Umbraco.Core.Exceptions; using System.Threading; using Umbraco.Core.Logging; @@ -11,6 +10,9 @@ namespace Umbraco.Core.IO { public class PhysicalFileSystem : IFileSystem { + private readonly IIOHelper _ioHelper; + private readonly ILogger _logger; + // the rooted, filesystem path, using directory separator chars, NOT ending with a separator // eg "c:" or "c:\path\to\site" or "\\server\path" private readonly string _rootPath; @@ -26,28 +28,35 @@ namespace Umbraco.Core.IO // virtualRoot should be "~/path/to/root" eg "~/Views" // the "~/" is mandatory. - public PhysicalFileSystem(string virtualRoot) + public PhysicalFileSystem(IIOHelper ioHelper, ILogger logger, string virtualRoot) { + _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + if (virtualRoot == null) throw new ArgumentNullException("virtualRoot"); if (virtualRoot.StartsWith("~/") == false) throw new ArgumentException("The virtualRoot argument must be a virtual path and start with '~/'"); - _rootPath = EnsureDirectorySeparatorChar(Current.IOHelper.MapPath(virtualRoot)).TrimEnd(Path.DirectorySeparatorChar); + _rootPath = EnsureDirectorySeparatorChar(_ioHelper.MapPath(virtualRoot)).TrimEnd(Path.DirectorySeparatorChar); _rootPathFwd = EnsureUrlSeparatorChar(_rootPath); - _rootUrl = EnsureUrlSeparatorChar(Current.IOHelper.ResolveUrl(virtualRoot)).TrimEnd('/'); + _rootUrl = EnsureUrlSeparatorChar(_ioHelper.ResolveUrl(virtualRoot)).TrimEnd('/'); } - public PhysicalFileSystem(string rootPath, string rootUrl) + public PhysicalFileSystem(IIOHelper ioHelper, ILogger logger, string rootPath, string rootUrl) { + _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + if (string.IsNullOrEmpty(rootPath)) throw new ArgumentNullOrEmptyException(nameof(rootPath)); if (string.IsNullOrEmpty(rootUrl)) throw new ArgumentNullOrEmptyException(nameof(rootUrl)); if (rootPath.StartsWith("~/")) throw new ArgumentException("The rootPath argument cannot be a virtual path and cannot start with '~/'"); + // rootPath should be... rooted, as in, it's a root path! if (Path.IsPathRooted(rootPath) == false) { // but the test suite App.config cannot really "root" anything so we have to do it here - var localRoot = Current.IOHelper.GetRootDirectorySafe(); + var localRoot = _ioHelper.GetRootDirectorySafe(); rootPath = Path.Combine(localRoot, rootPath); } @@ -73,11 +82,11 @@ namespace Umbraco.Core.IO } catch (UnauthorizedAccessException ex) { - Current.Logger.Error(ex, "Not authorized to get directories for '{Path}'", fullPath); + _logger.Error(ex, "Not authorized to get directories for '{Path}'", fullPath); } catch (DirectoryNotFoundException ex) { - Current.Logger.Error(ex, "Directory not found for '{Path}'", fullPath); + _logger.Error(ex, "Directory not found for '{Path}'", fullPath); } return Enumerable.Empty(); @@ -109,7 +118,7 @@ namespace Umbraco.Core.IO } catch (DirectoryNotFoundException ex) { - Current.Logger.Error(ex, "Directory not found for '{Path}'", fullPath); + _logger.Error(ex, "Directory not found for '{Path}'", fullPath); } } @@ -189,11 +198,11 @@ namespace Umbraco.Core.IO } catch (UnauthorizedAccessException ex) { - Current.Logger.Error(ex, "Not authorized to get directories for '{Path}'", fullPath); + _logger.Error(ex, "Not authorized to get directories for '{Path}'", fullPath); } catch (DirectoryNotFoundException ex) { - Current.Logger.Error(ex, "Directory not found for '{FullPath}'", fullPath); + _logger.Error(ex, "Directory not found for '{FullPath}'", fullPath); } return Enumerable.Empty(); @@ -226,7 +235,7 @@ namespace Umbraco.Core.IO } catch (FileNotFoundException ex) { - Current.Logger.Error(ex.InnerException, "DeleteFile failed with FileNotFoundException for '{Path}'", fullPath); + _logger.Error(ex.InnerException, "DeleteFile failed with FileNotFoundException for '{Path}'", fullPath); } } @@ -257,12 +266,12 @@ namespace Umbraco.Core.IO // if it starts with the root url, strip it and trim the starting slash to make it relative // eg "/Media/1234/img.jpg" => "1234/img.jpg" - if (Current.IOHelper.PathStartsWith(path, _rootUrl, '/')) + if (_ioHelper.PathStartsWith(path, _rootUrl, '/')) return path.Substring(_rootUrl.Length).TrimStart('/'); // if it starts with the root path, strip it and trim the starting slash to make it relative // eg "c:/websites/test/root/Media/1234/img.jpg" => "1234/img.jpg" - if (Current.IOHelper.PathStartsWith(path, _rootPathFwd, '/')) + if (_ioHelper.PathStartsWith(path, _rootPathFwd, '/')) return path.Substring(_rootPathFwd.Length).TrimStart('/'); // unchanged - what else? @@ -292,7 +301,7 @@ namespace Umbraco.Core.IO path = GetRelativePath(path); // if not already rooted, combine with the root path - if (Current.IOHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar) == false) + if (_ioHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar) == false) path = Path.Combine(_rootPath, path); // sanitize - GetFullPath will take care of any relative @@ -303,7 +312,7 @@ namespace Umbraco.Core.IO // at that point, path is within legal parts of the filesystem, ie we have // permissions to reach that path, but it may nevertheless be outside of // our root path, due to relative segments, so better check - if (Current.IOHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar)) + if (_ioHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar)) { // this says that 4.7.2 supports long paths - but Windows does not // https://docs.microsoft.com/en-us/dotnet/api/system.io.pathtoolongexception?view=netframework-4.7.2 diff --git a/src/Umbraco.Core/IO/ShadowFileSystem.cs b/src/Umbraco.Abstractions/IO/ShadowFileSystem.cs similarity index 100% rename from src/Umbraco.Core/IO/ShadowFileSystem.cs rename to src/Umbraco.Abstractions/IO/ShadowFileSystem.cs diff --git a/src/Umbraco.Core/IO/ShadowFileSystems.cs b/src/Umbraco.Abstractions/IO/ShadowFileSystems.cs similarity index 100% rename from src/Umbraco.Core/IO/ShadowFileSystems.cs rename to src/Umbraco.Abstractions/IO/ShadowFileSystems.cs diff --git a/src/Umbraco.Core/IO/ShadowWrapper.cs b/src/Umbraco.Abstractions/IO/ShadowWrapper.cs similarity index 89% rename from src/Umbraco.Core/IO/ShadowWrapper.cs rename to src/Umbraco.Abstractions/IO/ShadowWrapper.cs index 379da60e10..ff2af4a554 100644 --- a/src/Umbraco.Core/IO/ShadowWrapper.cs +++ b/src/Umbraco.Abstractions/IO/ShadowWrapper.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using Umbraco.Core.Composing; +using Umbraco.Core.Logging; namespace Umbraco.Core.IO { @@ -15,15 +16,19 @@ namespace Umbraco.Core.IO private readonly string _shadowPath; private ShadowFileSystem _shadowFileSystem; private string _shadowDir; + private readonly IIOHelper _ioHelper; + private readonly ILogger _logger; - public ShadowWrapper(IFileSystem innerFileSystem, string shadowPath, Func isScoped = null) + public ShadowWrapper(IFileSystem innerFileSystem, IIOHelper ioHelper, ILogger logger, string shadowPath, Func isScoped = null) { _innerFileSystem = innerFileSystem; + _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _shadowPath = shadowPath; _isScoped = isScoped; } - public static string CreateShadowId() + public static string CreateShadowId(IIOHelper ioHelper) { const int retries = 50; // avoid infinite loop const int idLength = 8; // 6 chars @@ -38,7 +43,7 @@ namespace Umbraco.Core.IO var id = GuidUtils.ToBase32String(Guid.NewGuid(), idLength); var virt = ShadowFsPath + "/" + id; - var shadowDir = Current.IOHelper.MapPath(virt); + var shadowDir = ioHelper.MapPath(virt); if (Directory.Exists(shadowDir)) continue; @@ -56,9 +61,9 @@ namespace Umbraco.Core.IO // in a single thread anyways var virt = ShadowFsPath + "/" + id + "/" + _shadowPath; - _shadowDir = Current.IOHelper.MapPath(virt); + _shadowDir = _ioHelper.MapPath(virt); Directory.CreateDirectory(_shadowDir); - var tempfs = new PhysicalFileSystem(virt); + var tempfs = new PhysicalFileSystem(_ioHelper, _logger, virt); _shadowFileSystem = new ShadowFileSystem(_innerFileSystem, tempfs); } @@ -83,7 +88,7 @@ namespace Umbraco.Core.IO // shadowPath make be path/to/dir, remove each dir = dir.Replace("/", "\\"); - var min = Current.IOHelper.MapPath(ShadowFsPath).Length; + var min = _ioHelper.MapPath(ShadowFsPath).Length; var pos = dir.LastIndexOf("\\", StringComparison.OrdinalIgnoreCase); while (pos > min) { diff --git a/src/Umbraco.Core/IO/SupportingFileSystems.cs b/src/Umbraco.Abstractions/IO/SupportingFileSystems.cs similarity index 100% rename from src/Umbraco.Core/IO/SupportingFileSystems.cs rename to src/Umbraco.Abstractions/IO/SupportingFileSystems.cs diff --git a/src/Umbraco.Core/IO/SystemFiles.cs b/src/Umbraco.Abstractions/IO/SystemFiles.cs similarity index 94% rename from src/Umbraco.Core/IO/SystemFiles.cs rename to src/Umbraco.Abstractions/IO/SystemFiles.cs index 132945d130..d71d59b850 100644 --- a/src/Umbraco.Core/IO/SystemFiles.cs +++ b/src/Umbraco.Abstractions/IO/SystemFiles.cs @@ -1,5 +1,4 @@ using System.IO; -using Umbraco.Core.Composing; using Umbraco.Core.Configuration; namespace Umbraco.Core.IO diff --git a/src/Umbraco.Core/IO/ViewHelper.cs b/src/Umbraco.Abstractions/IO/ViewHelper.cs similarity index 100% rename from src/Umbraco.Core/IO/ViewHelper.cs rename to src/Umbraco.Abstractions/IO/ViewHelper.cs diff --git a/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj b/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj index b3a1b4fa25..e7fb18b667 100644 --- a/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj +++ b/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj @@ -11,4 +11,13 @@ + + + <_Parameter1>Umbraco.Tests + + + <_Parameter1>Umbraco.Tests.Benchmarks + + + diff --git a/src/Umbraco.Core/Composing/CompositionExtensions/FileSystems.cs b/src/Umbraco.Core/Composing/CompositionExtensions/FileSystems.cs index 37754f296b..90a0f10fba 100644 --- a/src/Umbraco.Core/Composing/CompositionExtensions/FileSystems.cs +++ b/src/Umbraco.Core/Composing/CompositionExtensions/FileSystems.cs @@ -1,6 +1,7 @@ using Umbraco.Core.Compose; using Umbraco.Core.IO; using Umbraco.Core.IO.MediaPathSchemes; +using Umbraco.Core.Logging; namespace Umbraco.Core.Composing.CompositionExtensions { @@ -90,7 +91,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions // register the IFileSystem supporting the IMediaFileSystem // THIS IS THE ONLY THING THAT NEEDS TO CHANGE, IN ORDER TO REPLACE THE UNDERLYING FILESYSTEM // and, SupportingFileSystem.For() returns the underlying filesystem - composition.SetMediaFileSystem(() => new PhysicalFileSystem(Current.Configs.Global().UmbracoMediaPath)); + composition.SetMediaFileSystem(factory => new PhysicalFileSystem(factory.GetInstance(), factory.GetInstance(), Current.Configs.Global().UmbracoMediaPath)); return composition; } diff --git a/src/Umbraco.Core/IO/SystemDirectories.cs b/src/Umbraco.Core/IO/SystemDirectories.cs deleted file mode 100644 index bfdd3f33ed..0000000000 --- a/src/Umbraco.Core/IO/SystemDirectories.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Web; -using Umbraco.Core.Composing; - -namespace Umbraco.Core.IO -{ - //all paths has a starting but no trailing / - public class SystemDirectories - { - - - } -} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index eae73c28bc..8272bbd45c 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -178,11 +178,7 @@ - - - - @@ -327,11 +323,6 @@ - - - - - @@ -483,18 +474,6 @@ - - - - - - - - - - - - diff --git a/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs b/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs index ab9b2cf73d..5e826af5cc 100644 --- a/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs @@ -3,6 +3,7 @@ using System.IO; using System.Text; using System.Threading; using NUnit.Framework; +using Umbraco.Core.Composing; using Umbraco.Core.IO; @@ -13,7 +14,7 @@ namespace Umbraco.Tests.IO public class PhysicalFileSystemTests : AbstractFileSystemTests { public PhysicalFileSystemTests() - : base(new PhysicalFileSystem(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests"), + : base(new PhysicalFileSystem(Current.IOHelper, Current.Logger, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests"), "/Media/")) { } diff --git a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs index 163619ec05..8e204d1bfe 100644 --- a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs @@ -57,8 +57,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); Directory.CreateDirectory(path + "/ShadowTests/d1"); @@ -91,8 +91,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); Directory.CreateDirectory(path + "/ShadowTests/sub"); @@ -140,8 +140,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); File.WriteAllText(path + "/ShadowTests/f1.txt", "foo"); @@ -179,8 +179,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); Directory.CreateDirectory(path + "/ShadowTests/sub"); @@ -234,8 +234,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); Assert.Throws(() => @@ -253,8 +253,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); File.WriteAllText(path + "/ShadowTests/f2.txt", "foo"); @@ -292,8 +292,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) @@ -332,8 +332,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) @@ -354,8 +354,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); Directory.CreateDirectory(path + "/ShadowTests/sub/sub"); @@ -394,7 +394,7 @@ namespace Umbraco.Tests.IO var scopedFileSystems = false; - var phy = new PhysicalFileSystem(path, "ignore"); + var phy = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path, "ignore"); var container = Mock.Of(); var fileSystems = new FileSystems(container, logger, IOHelper.Default, SettingsForTests.GenerateMockGlobalSettings()) { IsScoped = () => scopedFileSystems }; @@ -408,7 +408,7 @@ namespace Umbraco.Tests.IO string id; // explicit shadow without scope does not work - sw.Shadow(id = ShadowWrapper.CreateShadowId()); + sw.Shadow(id = ShadowWrapper.CreateShadowId(Current.IOHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f2.txt", ms); @@ -419,7 +419,7 @@ namespace Umbraco.Tests.IO // shadow with scope but no complete does not complete scopedFileSystems = true; // pretend we have a scope - var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId()); + var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(Current.IOHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f3.txt", ms); @@ -441,7 +441,7 @@ namespace Umbraco.Tests.IO // shadow with scope and complete does complete scopedFileSystems = true; // pretend we have a scope - scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId()); + scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(Current.IOHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f4.txt", ms); @@ -457,7 +457,7 @@ namespace Umbraco.Tests.IO // test scope for "another thread" scopedFileSystems = true; // pretend we have a scope - scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId()); + scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(Current.IOHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f5.txt", ms); @@ -488,7 +488,7 @@ namespace Umbraco.Tests.IO var scopedFileSystems = false; - var phy = new PhysicalFileSystem(path, "ignore"); + var phy = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path, "ignore"); var container = Mock.Of(); var fileSystems = new FileSystems(container, logger, IOHelper.Default, SettingsForTests.GenerateMockGlobalSettings()) { IsScoped = () => scopedFileSystems }; @@ -502,7 +502,7 @@ namespace Umbraco.Tests.IO string id; scopedFileSystems = true; // pretend we have a scope - var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId()); + var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(Current.IOHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f2.txt", ms); @@ -541,7 +541,7 @@ namespace Umbraco.Tests.IO var scopedFileSystems = false; - var phy = new PhysicalFileSystem(path, "ignore"); + var phy = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path, "ignore"); var container = Mock.Of(); var fileSystems = new FileSystems(container, logger, IOHelper.Default, SettingsForTests.GenerateMockGlobalSettings()) { IsScoped = () => scopedFileSystems }; @@ -555,7 +555,7 @@ namespace Umbraco.Tests.IO string id; scopedFileSystems = true; // pretend we have a scope - var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId()); + var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(Current.IOHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f2.txt", ms); @@ -651,8 +651,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -683,8 +683,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -718,8 +718,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -750,8 +750,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -785,8 +785,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -832,8 +832,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -866,8 +866,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -905,8 +905,8 @@ namespace Umbraco.Tests.IO Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(path + "/ShadowTests/", "rootUrl"); - var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "rootUrl"); + var fs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowTests/", "rootUrl"); + var sfs = new PhysicalFileSystem(Current.IOHelper, Current.Logger, path + "/ShadowSystem/", "rootUrl"); var ss = new ShadowFileSystem(fs, sfs); // Act diff --git a/src/Umbraco.Tests/Models/MediaXmlTest.cs b/src/Umbraco.Tests/Models/MediaXmlTest.cs index 4b4b333e74..d8557230b6 100644 --- a/src/Umbraco.Tests/Models/MediaXmlTest.cs +++ b/src/Umbraco.Tests/Models/MediaXmlTest.cs @@ -31,12 +31,13 @@ namespace Umbraco.Tests.Models // reference, so static ctor runs, so event handlers register // and then, this will reset the width, height... because the file does not exist, of course ;-( var logger = Mock.Of(); + var ioHelper = Mock.Of(); var scheme = Mock.Of(); var config = Mock.Of(); var dataTypeService = Mock.Of(); var localizationService = Mock.Of(); - var mediaFileSystem = new MediaFileSystem(Mock.Of(), config, scheme, logger); + var mediaFileSystem = new MediaFileSystem(Mock.Of(), config, scheme, logger, ioHelper); var ignored = new FileUploadPropertyEditor(Mock.Of(), mediaFileSystem, config, dataTypeService, localizationService); var media = MockedMedia.CreateMediaImage(mediaType, -1); diff --git a/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs b/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs index 123e4c33ca..f21db872ed 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Persistence.Repositories { base.SetUp(); - _fileSystem = new PhysicalFileSystem(Constants.SystemDirectories.MvcViews + "/Partials/"); + _fileSystem = new PhysicalFileSystem(Current.IOHelper, Current.Logger, Constants.SystemDirectories.MvcViews + "/Partials/"); } protected override void Compose() diff --git a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs index 1c82287842..5754ad1a9f 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs @@ -29,7 +29,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(new GlobalSettings().UmbracoScriptsPath); + _fileSystem = new PhysicalFileSystem(Current.IOHelper, Current.Logger, new GlobalSettings().UmbracoScriptsPath); Mock.Get(_fileSystems).Setup(x => x.ScriptsFileSystem).Returns(_fileSystem); using (var stream = CreateStream("Umbraco.Sys.registerNamespace(\"Umbraco.Utils\");")) { diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs index ef28b42f05..59fa2230bd 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -28,7 +28,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(new GlobalSettings().UmbracoCssPath); + _fileSystem = new PhysicalFileSystem(Current.IOHelper, Current.Logger,new GlobalSettings().UmbracoCssPath); Mock.Get(_fileSystems).Setup(x => x.StylesheetsFileSystem).Returns(_fileSystem); var stream = CreateStream("body {background:#EE7600; color:#FFF;}"); _fileSystem.AddFile("styles.css", stream); diff --git a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs index b86719e7e1..00c80ee75f 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs @@ -36,7 +36,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - var viewsFileSystem = new PhysicalFileSystem(Constants.SystemDirectories.MvcViews); + var viewsFileSystem = new PhysicalFileSystem(Current.IOHelper, Current.Logger, Constants.SystemDirectories.MvcViews); Mock.Get(_fileSystems).Setup(x => x.MvcViewsFileSystem).Returns(viewsFileSystem); } @@ -527,7 +527,7 @@ namespace Umbraco.Tests.Persistence.Repositories _fileSystems = null; //Delete all files - var fsViews = new PhysicalFileSystem(Constants.SystemDirectories.MvcViews); + var fsViews = new PhysicalFileSystem(Current.IOHelper, Current.Logger, Constants.SystemDirectories.MvcViews); var views = fsViews.GetFiles("", "*.cshtml"); foreach (var file in views) fsViews.DeleteFile(file); diff --git a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs index 885aaeefb9..458690e08d 100644 --- a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs @@ -77,10 +77,11 @@ namespace Umbraco.Tests.PropertyEditors Current.Factory = composition.CreateFactory(); var logger = Mock.Of(); + var ioHelper = Mock.Of(); var scheme = Mock.Of(); var config = Mock.Of(); - var mediaFileSystem = new MediaFileSystem(Mock.Of(), config, scheme, logger); + var mediaFileSystem = new MediaFileSystem(Mock.Of(), config, scheme, logger, ioHelper); var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new ImageCropperPropertyEditor(Mock.Of(), mediaFileSystem, Mock.Of(), Mock.Of(), Mock.Of())) { Id = 1 }); diff --git a/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs b/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs index ece78c0852..dcac00e1b9 100644 --- a/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs @@ -53,7 +53,7 @@ namespace Umbraco.Tests.Scoping [TestCase(false)] public void CreateMediaTest(bool complete) { - var physMediaFileSystem = new PhysicalFileSystem(Current.IOHelper.MapPath("media"), "ignore"); + var physMediaFileSystem = new PhysicalFileSystem(Current.IOHelper, Current.Logger, Current.IOHelper.MapPath("media"), "ignore"); var mediaFileSystem = Current.MediaFileSystem; Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt")); @@ -86,7 +86,7 @@ namespace Umbraco.Tests.Scoping [Test] public void MultiThread() { - var physMediaFileSystem = new PhysicalFileSystem(Current.IOHelper.MapPath("media"), "ignore"); + var physMediaFileSystem = new PhysicalFileSystem(Current.IOHelper, Current.Logger, Current.IOHelper.MapPath("media"), "ignore"); var mediaFileSystem = Current.MediaFileSystem; var scopeProvider = ScopeProvider; diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 6d90d2e7d0..d3149b13d6 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -107,8 +107,9 @@ namespace Umbraco.Tests.TestHelpers var scheme = Mock.Of(); var config = Mock.Of(); + var ioHelper = Mock.Of(); - var mediaFileSystem = new MediaFileSystem(Mock.Of(), config, scheme, logger); + var mediaFileSystem = new MediaFileSystem(Mock.Of(), config, scheme, logger, ioHelper); var externalLoginService = GetLazyService(factory, c => new ExternalLoginService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); var publicAccessService = GetLazyService(factory, c => new PublicAccessService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index d1e2ab2f6d..8137e42180 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -340,10 +340,11 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(factory => TestObjects.GetFileSystemsMock()); var logger = Mock.Of(); + var ioHelper = Mock.Of(); var scheme = Mock.Of(); var config = Mock.Of(); - var mediaFileSystem = new MediaFileSystem(Mock.Of(), config, scheme, logger); + var mediaFileSystem = new MediaFileSystem(Mock.Of(), config, scheme, logger, ioHelper); Composition.RegisterUnique(factory => mediaFileSystem); // no factory (noop) diff --git a/src/Umbraco.Web/Editors/BackOfficeAssetsController.cs b/src/Umbraco.Web/Editors/BackOfficeAssetsController.cs index 53ba7e08ef..82ac270e9b 100644 --- a/src/Umbraco.Web/Editors/BackOfficeAssetsController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeAssetsController.cs @@ -2,9 +2,10 @@ using System.Collections.Generic; using System.Linq; using System.Web.Http; -using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.IO; +using Umbraco.Core.Logging; using Umbraco.Web.Mvc; namespace Umbraco.Web.Editors @@ -12,7 +13,14 @@ namespace Umbraco.Web.Editors [PluginController("UmbracoApi")] public class BackOfficeAssetsController : UmbracoAuthorizedJsonController { - private readonly IFileSystem _jsLibFileSystem = new PhysicalFileSystem(Current.Configs.Global().UmbracoPath + Current.IOHelper.DirSepChar + "lib"); + private readonly IFileSystem _jsLibFileSystem; + + public BackOfficeAssetsController(IIOHelper ioHelper, ILogger logger, IGlobalSettings globalSettings) + { + _jsLibFileSystem = new PhysicalFileSystem(ioHelper, logger, globalSettings.UmbracoPath + Current.IOHelper.DirSepChar + "lib"); + } + + [HttpGet] public object GetSupportedLocales() diff --git a/src/Umbraco.Web/Trees/FilesTreeController.cs b/src/Umbraco.Web/Trees/FilesTreeController.cs index ae951bebf4..2faf5c753b 100644 --- a/src/Umbraco.Web/Trees/FilesTreeController.cs +++ b/src/Umbraco.Web/Trees/FilesTreeController.cs @@ -1,5 +1,6 @@ using Umbraco.Core; using Umbraco.Core.IO; +using Umbraco.Core.Logging; using Umbraco.Web.Models.Trees; namespace Umbraco.Web.Trees @@ -8,7 +9,16 @@ namespace Umbraco.Web.Trees [CoreTree] public class FilesTreeController : FileSystemTreeController { - protected override IFileSystem FileSystem => new PhysicalFileSystem("~/"); + private readonly IIOHelper _ioHelper; + private readonly ILogger _logger; + + public FilesTreeController(IIOHelper ioHelper, ILogger logger) + { + _ioHelper = ioHelper; + _logger = logger; + } + + protected override IFileSystem FileSystem => new PhysicalFileSystem(_ioHelper, _logger, "~/"); private static readonly string[] ExtensionsStatic = { "*" };