From 2309bb9d5bfaeb3b77112a256f71946ecf9be470 Mon Sep 17 00:00:00 2001 From: Benjamin Carleski Date: Wed, 18 Nov 2020 08:10:16 -0800 Subject: [PATCH] Finish removing IOHelper.MapPath references --- .../Compose/ManifestWatcherComponent.cs | 1 - .../Install/FilePermissionHelper.cs | 12 ++-- .../Manifest/ManifestParser.cs | 13 ++-- .../RichTextEditorPastedImages.cs | 9 +-- .../Services/Implement/PackagingService.cs | 12 ++-- .../Manifest/ManifestParserTests.cs | 2 +- src/Umbraco.Tests/IO/ShadowFileSystemTests.cs | 72 +++++++++---------- .../Packaging/PackageInstallationTest.cs | 2 +- .../PublishedContentTestBase.cs | 2 +- .../PublishedContent/PublishedContentTests.cs | 2 +- .../Controllers/CodeFileController.cs | 9 +-- .../Controllers/ContentTypeController.cs | 8 +-- .../Macros/MacroRenderer.cs | 12 ++-- .../Macros/PartialViewMacroEngine.cs | 10 +-- .../WebApi/HttpActionContextExtensions.cs | 7 +- .../CDF/ClientDependencyConfiguration.cs | 6 +- .../CDF/ClientDependencyRuntimeMinifier.cs | 13 ++-- 17 files changed, 93 insertions(+), 99 deletions(-) diff --git a/src/Umbraco.Infrastructure/Compose/ManifestWatcherComponent.cs b/src/Umbraco.Infrastructure/Compose/ManifestWatcherComponent.cs index 0c585f04b4..dd3a800821 100644 --- a/src/Umbraco.Infrastructure/Compose/ManifestWatcherComponent.cs +++ b/src/Umbraco.Infrastructure/Compose/ManifestWatcherComponent.cs @@ -2,7 +2,6 @@ using Microsoft.Extensions.Logging; using Umbraco.Core.Composing; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; using Umbraco.Core.Manifest; using Umbraco.Net; diff --git a/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs b/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs index 7a20a1189e..a12634f01d 100644 --- a/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs +++ b/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs @@ -4,12 +4,12 @@ using System.Linq; using System.IO; using System.Security.AccessControl; using Umbraco.Core; -using Umbraco.Core.Configuration; using Umbraco.Core.Install; using Umbraco.Core.IO; using Umbraco.Web.PublishedCache; using Umbraco.Core.Configuration.Models; using Microsoft.Extensions.Options; +using Umbraco.Core.Hosting; namespace Umbraco.Web.Install { @@ -23,12 +23,14 @@ namespace Umbraco.Web.Install private readonly string[] _permissionFiles = { }; private readonly GlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; + private readonly IHostingEnvironment _hostingEnvironment; private readonly IPublishedSnapshotService _publishedSnapshotService; - public FilePermissionHelper(IOptions globalSettings, IIOHelper ioHelper, IPublishedSnapshotService publishedSnapshotService) + public FilePermissionHelper(IOptions globalSettings, IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, IPublishedSnapshotService publishedSnapshotService) { _globalSettings = globalSettings.Value; _ioHelper = ioHelper; + _hostingEnvironment = hostingEnvironment; _publishedSnapshotService = publishedSnapshotService; _permissionDirs = new[] { _globalSettings.UmbracoCssPath, Constants.SystemDirectories.Config, Constants.SystemDirectories.Data, _globalSettings.UmbracoMediaPath, Constants.SystemDirectories.Preview }; _packagesPermissionsDirs = new[] { Constants.SystemDirectories.Bin, _globalSettings.UmbracoPath, Constants.SystemDirectories.Packages }; @@ -140,7 +142,7 @@ namespace Umbraco.Web.Install { try { - var path = _ioHelper.MapPath(dir + "/" + _ioHelper.CreateRandomFileName()); + var path = _hostingEnvironment.MapPathContentRoot(dir + "/" + _ioHelper.CreateRandomFileName()); Directory.CreateDirectory(path); Directory.Delete(path); return true; @@ -163,7 +165,7 @@ namespace Umbraco.Web.Install { try { - var dirPath = _ioHelper.MapPath(dir); + var dirPath = _hostingEnvironment.MapPathContentRoot(dir); if (Directory.Exists(dirPath) == false) return true; @@ -228,7 +230,7 @@ namespace Umbraco.Web.Install { try { - var path = _ioHelper.MapPath(file); + var path = _hostingEnvironment.MapPathContentRoot(file); File.AppendText(path).Close(); return true; } diff --git a/src/Umbraco.Infrastructure/Manifest/ManifestParser.cs b/src/Umbraco.Infrastructure/Manifest/ManifestParser.cs index 7392506d2b..eec83dffef 100644 --- a/src/Umbraco.Infrastructure/Manifest/ManifestParser.cs +++ b/src/Umbraco.Infrastructure/Manifest/ManifestParser.cs @@ -6,6 +6,7 @@ using System.Text; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Umbraco.Core.Cache; +using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Serialization; @@ -20,6 +21,8 @@ namespace Umbraco.Core.Manifest public class ManifestParser : IManifestParser { private readonly ILoggerFactory _loggerFactory; + private readonly IIOHelper _ioHelper; + private readonly IHostingEnvironment _hostingEnvironment; private readonly IJsonSerializer _jsonSerializer; private readonly ILocalizedTextService _localizedTextService; private readonly IShortStringHelper _shortStringHelper; @@ -27,7 +30,6 @@ namespace Umbraco.Core.Manifest private readonly IAppPolicyCache _cache; private readonly ILogger _logger; - private readonly IIOHelper _ioHelper; private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; private readonly ManifestValueValidatorCollection _validators; @@ -45,12 +47,13 @@ namespace Umbraco.Core.Manifest ILogger logger, ILoggerFactory loggerFactory, IIOHelper ioHelper, + IHostingEnvironment hostingEnvironment, IDataTypeService dataTypeService, ILocalizationService localizationService, IJsonSerializer jsonSerializer, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper) - : this(appCaches, validators, filters, "~/App_Plugins", logger, loggerFactory, ioHelper, dataTypeService, localizationService) + : this(appCaches, validators, filters, "~/App_Plugins", logger, loggerFactory, ioHelper, hostingEnvironment, dataTypeService, localizationService) { _loggerFactory = loggerFactory; _jsonSerializer = jsonSerializer; @@ -61,11 +64,10 @@ namespace Umbraco.Core.Manifest /// /// Initializes a new instance of the class. /// - private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger logger, ILoggerFactory loggerFactory, IIOHelper ioHelper, IDataTypeService dataTypeService, ILocalizationService localizationService) + private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger logger, ILoggerFactory loggerFactory, IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, IDataTypeService dataTypeService, ILocalizationService localizationService) { if (appCaches == null) throw new ArgumentNullException(nameof(appCaches)); _cache = appCaches.RuntimeCache; - _ioHelper = ioHelper; _dataTypeService = dataTypeService; _localizationService = localizationService; _validators = validators ?? throw new ArgumentNullException(nameof(validators)); @@ -75,6 +77,7 @@ namespace Umbraco.Core.Manifest _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); _ioHelper = ioHelper; + _hostingEnvironment = hostingEnvironment; Path = path; @@ -84,7 +87,7 @@ namespace Umbraco.Core.Manifest public string Path { get => _path; - set => _path = value.StartsWith("~/") ? _ioHelper.MapPath(value) : value; + set => _path = value.StartsWith("~/") ? _hostingEnvironment.MapPathContentRoot(value) : value; } /// diff --git a/src/Umbraco.Infrastructure/PropertyEditors/RichTextEditorPastedImages.cs b/src/Umbraco.Infrastructure/PropertyEditors/RichTextEditorPastedImages.cs index b5a0972c3e..4ccd7dfc3f 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/RichTextEditorPastedImages.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/RichTextEditorPastedImages.cs @@ -13,6 +13,7 @@ using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Web.Models; using Umbraco.Web.Routing; +using Umbraco.Core.Hosting; namespace Umbraco.Web.PropertyEditors { @@ -20,7 +21,7 @@ namespace Umbraco.Web.PropertyEditors { private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly ILogger _logger; - private readonly IIOHelper _ioHelper; + private readonly IHostingEnvironment _hostingEnvironment; private readonly IMediaService _mediaService; private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; private readonly IMediaFileSystem _mediaFileSystem; @@ -30,11 +31,11 @@ namespace Umbraco.Web.PropertyEditors const string TemporaryImageDataAttribute = "data-tmpimg"; - public RichTextEditorPastedImages(IUmbracoContextAccessor umbracoContextAccessor, ILogger logger, IIOHelper ioHelper, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, IPublishedUrlProvider publishedUrlProvider, IJsonSerializer serializer) + public RichTextEditorPastedImages(IUmbracoContextAccessor umbracoContextAccessor, ILogger logger, IHostingEnvironment hostingEnvironment, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, IPublishedUrlProvider publishedUrlProvider, IJsonSerializer serializer) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _ioHelper = ioHelper; + _hostingEnvironment = hostingEnvironment; _mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService)); _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider ?? throw new ArgumentNullException(nameof(contentTypeBaseServiceProvider)); _mediaFileSystem = mediaFileSystem; @@ -73,7 +74,7 @@ namespace Umbraco.Web.PropertyEditors if (string.IsNullOrEmpty(tmpImgPath)) continue; - var absoluteTempImagePath = _ioHelper.MapPath(tmpImgPath); + var absoluteTempImagePath = _hostingEnvironment.MapPathContentRoot(tmpImgPath); var fileName = Path.GetFileName(absoluteTempImagePath); var safeFileName = fileName.ToSafeFileName(_shortStringHelper); diff --git a/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs b/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs index 238258b8c2..a286a1cf50 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs @@ -5,10 +5,8 @@ using System.Linq; using System.Net.Http; using System.Threading.Tasks; using Semver; -using Umbraco.Core.Composing; using Umbraco.Core.Events; -using Umbraco.Core.Exceptions; -using Umbraco.Core.IO; +using Umbraco.Core.Hosting; using Umbraco.Core.Models; using Umbraco.Core.Models.Packaging; using Umbraco.Core.Packaging; @@ -22,7 +20,7 @@ namespace Umbraco.Core.Services.Implement public class PackagingService : IPackagingService { private readonly IPackageInstallation _packageInstallation; - private readonly IIOHelper _ioHelper; + private readonly IHostingEnvironment _hostingEnvironment; private readonly IAuditService _auditService; private readonly ICreatedPackagesRepository _createdPackages; private readonly IInstalledPackagesRepository _installedPackages; @@ -33,13 +31,13 @@ namespace Umbraco.Core.Services.Implement ICreatedPackagesRepository createdPackages, IInstalledPackagesRepository installedPackages, IPackageInstallation packageInstallation, - IIOHelper ioHelper) + IHostingEnvironment hostingEnvironment) { _auditService = auditService; _createdPackages = createdPackages; _installedPackages = installedPackages; _packageInstallation = packageInstallation; - _ioHelper = ioHelper; + _hostingEnvironment = hostingEnvironment; } #region Package Files @@ -66,7 +64,7 @@ namespace Umbraco.Core.Services.Implement //successful if (bytes.Length > 0) { - var packagePath = _ioHelper.MapPath(Constants.SystemDirectories.Packages); + var packagePath = _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.Packages); // Check for package directory if (Directory.Exists(packagePath) == false) diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs index 4bc531944e..e1a34e38a3 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs @@ -38,7 +38,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Manifest }; _ioHelper = TestHelper.IOHelper; var loggerFactory = NullLoggerFactory.Instance; - _parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty()), loggerFactory.CreateLogger(), loggerFactory, _ioHelper, Mock.Of(), Mock.Of(), new JsonNetSerializer(), Mock.Of(), Mock.Of()); + _parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty()), loggerFactory.CreateLogger(), loggerFactory, _ioHelper, TestHelper.GetHostingEnvironment(), Mock.Of(), Mock.Of(), new JsonNetSerializer(), Mock.Of(), Mock.Of()); } [Test] diff --git a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs index 04900abaf0..c42205d545 100644 --- a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs @@ -32,7 +32,7 @@ namespace Umbraco.Tests.IO public void SetUp() { SafeCallContext.Clear(); - ClearFiles(_ioHelper); + ClearFiles(_hostingEnvironment); FileSystems.ResetShadowId(); } @@ -40,14 +40,14 @@ namespace Umbraco.Tests.IO public void TearDown() { SafeCallContext.Clear(); - ClearFiles(TestHelper.IOHelper); + ClearFiles(_hostingEnvironment); FileSystems.ResetShadowId(); } - private static void ClearFiles(IIOHelper _ioHelper) + private static void ClearFiles(IHostingEnvironment hostingEnvironment) { - TestHelper.DeleteDirectory(_ioHelper.MapPath("FileSysTests")); - TestHelper.DeleteDirectory(_ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); + TestHelper.DeleteDirectory(hostingEnvironment.MapPathContentRoot("FileSysTests")); + TestHelper.DeleteDirectory(hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); } private static string NormPath(string path) @@ -58,7 +58,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteDirectory() { - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -92,7 +92,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteDirectoryInDir() { - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -141,7 +141,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteFile() { - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -180,7 +180,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteFileInDir() { - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); @@ -236,7 +236,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowCantCreateFile() { - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -255,7 +255,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowCreateFile() { - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -294,7 +294,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowCreateFileInDir() { - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -334,7 +334,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowAbort() { - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -356,7 +356,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowComplete() { - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -393,8 +393,8 @@ namespace Umbraco.Tests.IO public void ShadowScopeComplete() { var loggerFactory = NullLoggerFactory.Instance; - var path = _ioHelper.MapPath("FileSysTests"); - var shadowfs = _ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); + var shadowfs = _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); Directory.CreateDirectory(shadowfs); @@ -415,7 +415,7 @@ namespace Umbraco.Tests.IO string id; // explicit shadow without scope does not work - sw.Shadow(id = ShadowWrapper.CreateShadowId(_ioHelper)); + sw.Shadow(id = ShadowWrapper.CreateShadowId(_hostingEnvironment)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f2.txt", ms); @@ -426,7 +426,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(_ioHelper)); + var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_hostingEnvironment)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f3.txt", ms); @@ -448,7 +448,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(_ioHelper)); + scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_hostingEnvironment)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f4.txt", ms); @@ -464,7 +464,7 @@ namespace Umbraco.Tests.IO // test scope for "another thread" scopedFileSystems = true; // pretend we have a scope - scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_ioHelper)); + scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_hostingEnvironment)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f5.txt", ms); @@ -487,8 +487,8 @@ namespace Umbraco.Tests.IO [Test] public void ShadowScopeCompleteWithFileConflict() { - var path = _ioHelper.MapPath("FileSysTests"); - var shadowfs = _ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); + var shadowfs = _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); var scopedFileSystems = false; @@ -508,7 +508,7 @@ namespace Umbraco.Tests.IO string id; scopedFileSystems = true; // pretend we have a scope - var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_ioHelper)); + var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_hostingEnvironment)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f2.txt", ms); @@ -539,8 +539,8 @@ namespace Umbraco.Tests.IO [Test] public void ShadowScopeCompleteWithDirectoryConflict() { - var path = _ioHelper.MapPath("FileSysTests"); - var shadowfs = _ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); + var shadowfs = _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); var scopedFileSystems = false; @@ -560,7 +560,7 @@ namespace Umbraco.Tests.IO string id; scopedFileSystems = true; // pretend we have a scope - var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_ioHelper)); + var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_hostingEnvironment)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f2.txt", ms); @@ -608,7 +608,7 @@ namespace Umbraco.Tests.IO [Test] public void GetFilesReturnsChildrenOnly() { - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); File.WriteAllText(path + "/f1.txt", "foo"); Directory.CreateDirectory(path + "/test"); @@ -630,7 +630,7 @@ namespace Umbraco.Tests.IO [Test] public void DeleteDirectoryAndFiles() { - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); File.WriteAllText(path + "/f1.txt", "foo"); Directory.CreateDirectory(path + "/test"); @@ -651,7 +651,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFiles() { // Arrange - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -683,7 +683,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingEmptyFilter() { // Arrange - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -718,7 +718,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingNullFilter() { // Arrange - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -750,7 +750,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingWildcardFilter() { // Arrange - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -785,7 +785,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingSingleCharacterFilter() { // Arrange - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -832,7 +832,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFullPath() { // Arrange - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -866,7 +866,7 @@ namespace Umbraco.Tests.IO public void ShadowGetRelativePath() { // Arrange - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -905,7 +905,7 @@ namespace Umbraco.Tests.IO public void ShadowGetUrl() { // Arrange - var path = _ioHelper.MapPath("FileSysTests"); + var path = _hostingEnvironment.MapPathContentRoot("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); diff --git a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs index d09faf6757..51d077d89f 100644 --- a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs +++ b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs @@ -66,7 +66,7 @@ namespace Umbraco.Tests.Packaging private IPackageInstallation PackageInstallation => new PackageInstallation( PackageDataInstallation, - new PackageFileInstallation(Parser, IOHelper, ProfilingLogger), + new PackageFileInstallation(Parser, IOHelper, HostingEnvironment, ProfilingLogger), Parser, Mock.Of(), //we don't want to extract package files to the real root, so extract to a test folder Mock.Of(x => x.ApplicationPhysicalPath == _testBaseFolder.FullName)); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs index 0e7bdbc068..582411635d 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs @@ -52,7 +52,7 @@ namespace Umbraco.Tests.PublishedContent var serializer = new ConfigurationEditorJsonSerializer(); var imageSourceParser = new HtmlImageSourceParser(publishedUrlProvider); - var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, loggerFactory.CreateLogger(), IOHelper, Mock.Of(), Mock.Of(), Mock.Of(), ShortStringHelper, publishedUrlProvider, serializer); + var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, loggerFactory.CreateLogger(), HostingEnvironment, Mock.Of(), Mock.Of(), Mock.Of(), ShortStringHelper, publishedUrlProvider, serializer); var localLinkParser = new HtmlLocalLinkParser(umbracoContextAccessor, publishedUrlProvider); var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new RichTextPropertyEditor( diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index e75abf500d..b8de80fdb1 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -57,7 +57,7 @@ namespace Umbraco.Tests.PublishedContent var publishedUrlProvider = Mock.Of(); var imageSourceParser = new HtmlImageSourceParser(publishedUrlProvider); var serializer = new ConfigurationEditorJsonSerializer(); - var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, loggerFactory.CreateLogger(), IOHelper, mediaService, contentTypeBaseServiceProvider, mediaFileService, ShortStringHelper, publishedUrlProvider, serializer); + var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, loggerFactory.CreateLogger(), HostingEnvironment, mediaService, contentTypeBaseServiceProvider, mediaFileService, ShortStringHelper, publishedUrlProvider, serializer); var linkParser = new HtmlLocalLinkParser(umbracoContextAccessor, publishedUrlProvider); var localizationService = Mock.Of(); diff --git a/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs b/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs index 4bf76a108a..b4143831d5 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Mapping; using Umbraco.Core.Models; @@ -31,7 +32,7 @@ namespace Umbraco.Web.BackOffice.Controllers [UmbracoApplicationAuthorize(Constants.Applications.Settings)] public class CodeFileController : BackOfficeNotificationsController { - private readonly IIOHelper _ioHelper; + private readonly IHostingEnvironment _hostingEnvironment; private readonly IFileSystems _fileSystems; private readonly IFileService _fileService; private readonly IUmbracoContextAccessor _umbracoContextAccessor; @@ -41,7 +42,7 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly GlobalSettings _globalSettings; public CodeFileController( - IIOHelper ioHelper, + IHostingEnvironment hostingEnvironment, IFileSystems fileSystems, IFileService fileService, IUmbracoContextAccessor umbracoContextAccessor, @@ -50,7 +51,7 @@ namespace Umbraco.Web.BackOffice.Controllers IShortStringHelper shortStringHelper, IOptions globalSettings) { - _ioHelper = ioHelper; + _hostingEnvironment = hostingEnvironment; _fileSystems = fileSystems; _fileService = fileService; _umbracoContextAccessor = umbracoContextAccessor; @@ -655,7 +656,7 @@ namespace Umbraco.Web.BackOffice.Controllers private bool IsDirectory(string virtualPath, string systemDirectory) { - var path = _ioHelper.MapPath(systemDirectory + "/" + virtualPath); + var path = _hostingEnvironment.MapPathContentRoot(systemDirectory + "/" + virtualPath); var dirInfo = new DirectoryInfo(path); return dirInfo.Attributes == FileAttributes.Directory; } diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs index 9d18727c62..317464e46f 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs @@ -12,10 +12,8 @@ using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Umbraco.Core; -using Umbraco.Core.Configuration; using Umbraco.Core.Dictionary; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; using Umbraco.Core.Models; using Umbraco.Core.Packaging; using Umbraco.Core.PropertyEditors; @@ -31,7 +29,6 @@ using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.Common.Attributes; using Umbraco.Web.Common.Exceptions; using Umbraco.Web.Editors; -using Umbraco.Web.Security; using ContentType = Umbraco.Core.Models.ContentType; using Umbraco.Core.Configuration.Models; using Microsoft.Extensions.Options; @@ -55,7 +52,6 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly GlobalSettings _globalSettings; private readonly PropertyEditorCollection _propertyEditors; private readonly IScopeProvider _scopeProvider; - private readonly IIOHelper _ioHelper; private readonly IContentTypeService _contentTypeService; private readonly UmbracoMapper _umbracoMapper; private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor; @@ -84,7 +80,6 @@ namespace Umbraco.Web.BackOffice.Controllers IOptions globalSettings, PropertyEditorCollection propertyEditors, IScopeProvider scopeProvider, - IIOHelper ioHelper, IBackOfficeSecurityAccessor backofficeSecurityAccessor, IDataTypeService dataTypeService, IShortStringHelper shortStringHelper, @@ -111,7 +106,6 @@ namespace Umbraco.Web.BackOffice.Controllers _globalSettings = globalSettings.Value; _propertyEditors = propertyEditors; _scopeProvider = scopeProvider; - _ioHelper = ioHelper; _contentTypeService = contentTypeService; _umbracoMapper = umbracoMapper; _backofficeSecurityAccessor = backofficeSecurityAccessor; @@ -618,7 +612,7 @@ namespace Umbraco.Web.BackOffice.Controllers [HttpPost] public IActionResult Import(string file) { - var filePath = Path.Combine(_ioHelper.MapPath(Core.Constants.SystemDirectories.Data), file); + var filePath = Path.Combine(_hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.Data), file); if (string.IsNullOrEmpty(file) || !System.IO.File.Exists(filePath)) { return NotFound(); diff --git a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs index c0d2fdbdd4..448a216e40 100644 --- a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs @@ -10,13 +10,13 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Events; -using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Macros; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Web.Common.Macros; +using Umbraco.Core.Hosting; namespace Umbraco.Web.Macros { @@ -29,7 +29,7 @@ namespace Umbraco.Web.Macros private readonly ILocalizedTextService _textService; private readonly AppCaches _appCaches; private readonly IMacroService _macroService; - private readonly IIOHelper _ioHelper; + private readonly IHostingEnvironment _hostingEnvironment; private readonly ICookieManager _cookieManager; private readonly IMemberUserKeyProvider _memberUserKeyProvider; private readonly ISessionManager _sessionManager; @@ -44,7 +44,7 @@ namespace Umbraco.Web.Macros ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, - IIOHelper ioHelper, + IHostingEnvironment hostingEnvironment, ICookieManager cookieManager, IMemberUserKeyProvider memberUserKeyProvider, ISessionManager sessionManager, @@ -58,7 +58,7 @@ namespace Umbraco.Web.Macros _textService = textService; _appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); _macroService = macroService ?? throw new ArgumentNullException(nameof(macroService)); - _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); + _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _cookieManager = cookieManager; _memberUserKeyProvider = memberUserKeyProvider; _sessionManager = sessionManager; @@ -183,7 +183,7 @@ namespace Umbraco.Web.Macros var filename = GetMacroFileName(model); if (filename == null) return null; - var mapped = _ioHelper.MapPath(filename); + var mapped = _hostingEnvironment.MapPathContentRoot(filename); if (mapped == null) return null; var file = new FileInfo(mapped); @@ -353,7 +353,7 @@ namespace Umbraco.Web.Macros /// The text output of the macro execution. private MacroContent ExecutePartialView(MacroModel macro, IPublishedContent content) { - var engine = new PartialViewMacroEngine(_umbracoContextAccessor, _httpContextAccessor, _ioHelper); + var engine = new PartialViewMacroEngine(_umbracoContextAccessor, _httpContextAccessor, _hostingEnvironment); return engine.Execute(macro, content); } diff --git a/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs b/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs index 3566ee48ee..db1658e962 100644 --- a/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs +++ b/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs @@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Mvc.ViewEngines; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; -using Umbraco.Core.IO; +using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; using Umbraco.Extensions; using Umbraco.Web.Macros; @@ -26,16 +26,16 @@ namespace Umbraco.Web.Common.Macros public class PartialViewMacroEngine { private readonly IHttpContextAccessor _httpContextAccessor; - private readonly IIOHelper _ioHelper; + private readonly IHostingEnvironment _hostingEnvironment; private readonly Func _getUmbracoContext; public PartialViewMacroEngine( IUmbracoContextAccessor umbracoContextAccessor, IHttpContextAccessor httpContextAccessor, - IIOHelper ioHelper) + IHostingEnvironment hostingEnvironment) { _httpContextAccessor = httpContextAccessor; - _ioHelper = ioHelper; + _hostingEnvironment = hostingEnvironment; _getUmbracoContext = () => { @@ -122,7 +122,7 @@ namespace Umbraco.Web.Common.Macros } private string GetVirtualPathFromPhysicalPath(string physicalPath) { - var rootpath = _ioHelper.MapPath("~/"); + var rootpath = _hostingEnvironment.MapPathContentRoot("~/"); physicalPath = physicalPath.Replace(rootpath, ""); physicalPath = physicalPath.Replace("\\", "/"); return "~/" + physicalPath; diff --git a/src/Umbraco.Web/WebApi/HttpActionContextExtensions.cs b/src/Umbraco.Web/WebApi/HttpActionContextExtensions.cs index f41dcac6eb..a3553fb766 100644 --- a/src/Umbraco.Web/WebApi/HttpActionContextExtensions.cs +++ b/src/Umbraco.Web/WebApi/HttpActionContextExtensions.cs @@ -8,8 +8,7 @@ using System.Web.Http.Controllers; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using Umbraco.Web.Composing; -using Umbraco.Core.IO; -using Umbraco.Core; +using Umbraco.Core.Hosting; namespace Umbraco.Web.WebApi { @@ -61,8 +60,8 @@ namespace Umbraco.Web.WebApi throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } - var ioHelper = Current.Factory.GetRequiredService(); - var root = ioHelper.MapPath(rootVirtualPath); + var hostingEnvironment = Current.Factory.GetRequiredService(); + var root = hostingEnvironment.MapPathContentRoot(rootVirtualPath); //ensure it exists Directory.CreateDirectory(root); var provider = new MultipartFormDataStreamProvider(root); diff --git a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyConfiguration.cs b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyConfiguration.cs index 2f427a8949..81dd05c25a 100644 --- a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyConfiguration.cs +++ b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyConfiguration.cs @@ -10,7 +10,7 @@ using Microsoft.Extensions.Logging; using ClientDependency.Core.CompositeFiles.Providers; using ClientDependency.Core.Config; using Semver; -using Umbraco.Core.IO; +using Umbraco.Core.Hosting; namespace Umbraco.Web.WebAssets.CDF { @@ -28,11 +28,11 @@ namespace Umbraco.Web.WebAssets.CDF set => XmlFileMapper.FileMapDefaultFolder = value; } - public ClientDependencyConfiguration(ILogger logger, IIOHelper ioHelper) + public ClientDependencyConfiguration(ILogger logger, IHostingEnvironment hostingEnvironment) { if (logger == null) throw new ArgumentNullException("logger"); _logger = logger; - _fileName = ioHelper.MapPath(string.Format("{0}/ClientDependency.config", Core.Constants.SystemDirectories.Config)); + _fileName = hostingEnvironment.MapPathContentRoot(string.Format("{0}/ClientDependency.config", Core.Constants.SystemDirectories.Config)); } /// diff --git a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyRuntimeMinifier.cs b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyRuntimeMinifier.cs index 1bdb1bf945..c72887b4d2 100644 --- a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyRuntimeMinifier.cs +++ b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyRuntimeMinifier.cs @@ -4,25 +4,22 @@ using System.IO; using System.Linq; using System.Reflection; using System.Threading.Tasks; -using System.Web; using Microsoft.Extensions.Logging; using ClientDependency.Core; using ClientDependency.Core.CompositeFiles; using ClientDependency.Core.Config; using Umbraco.Core.Configuration; -using Umbraco.Core.IO; -using Umbraco.Core.Manifest; -using Umbraco.Core.PropertyEditors; using Umbraco.Core.WebAssets; using CssFile = ClientDependency.Core.CssFile; using JavascriptFile = ClientDependency.Core.JavascriptFile; +using Umbraco.Core.Hosting; namespace Umbraco.Web.WebAssets.CDF { public class ClientDependencyRuntimeMinifier : IRuntimeMinifier { private readonly IHttpContextAccessor _httpContextAccessor; - private readonly IIOHelper _ioHelper; + private readonly IHostingEnvironment _hostingEnvironment; private readonly ILoggerFactory _loggerFactory; private readonly ILogger _logger; private readonly IUmbracoVersion _umbracoVersion; @@ -31,12 +28,12 @@ namespace Umbraco.Web.WebAssets.CDF public ClientDependencyRuntimeMinifier( IHttpContextAccessor httpContextAccessor, - IIOHelper ioHelper, + IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory, IUmbracoVersion umbracoVersion) { _httpContextAccessor = httpContextAccessor; - _ioHelper = ioHelper; + _hostingEnvironment = hostingEnvironment; _loggerFactory = loggerFactory; _logger = _loggerFactory.CreateLogger(); _umbracoVersion = umbracoVersion; @@ -109,7 +106,7 @@ namespace Umbraco.Web.WebAssets.CDF public void Reset() { // Update ClientDependency version - var clientDependencyConfig = new ClientDependencyConfiguration(_loggerFactory.CreateLogger(), _ioHelper); + var clientDependencyConfig = new ClientDependencyConfiguration(_loggerFactory.CreateLogger(), _hostingEnvironment); var clientDependencyUpdated = clientDependencyConfig.UpdateVersionNumber( _umbracoVersion.SemanticVersion, DateTime.UtcNow, "yyyyMMdd"); // Delete ClientDependency temp directories to make sure we get fresh caches