Finish removing IOHelper.MapPath references

This commit is contained in:
Benjamin Carleski
2020-11-18 08:10:16 -08:00
parent 7583c1fb06
commit 2309bb9d5b
17 changed files with 93 additions and 99 deletions

View File

@@ -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;

View File

@@ -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> globalSettings, IIOHelper ioHelper, IPublishedSnapshotService publishedSnapshotService)
public FilePermissionHelper(IOptions<GlobalSettings> 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;
}

View File

@@ -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<ManifestParser> _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<ManifestParser> 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
/// <summary>
/// Initializes a new instance of the <see cref="ManifestParser"/> class.
/// </summary>
private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger<ManifestParser> logger, ILoggerFactory loggerFactory, IIOHelper ioHelper, IDataTypeService dataTypeService, ILocalizationService localizationService)
private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger<ManifestParser> 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;
}
/// <summary>

View File

@@ -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<RichTextEditorPastedImages> _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<RichTextEditorPastedImages> logger, IIOHelper ioHelper, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, IPublishedUrlProvider publishedUrlProvider, IJsonSerializer serializer)
public RichTextEditorPastedImages(IUmbracoContextAccessor umbracoContextAccessor, ILogger<RichTextEditorPastedImages> 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);

View File

@@ -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)

View File

@@ -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<IManifestFilter>()), loggerFactory.CreateLogger<ManifestParser>(), loggerFactory, _ioHelper, Mock.Of<IDataTypeService>(), Mock.Of<ILocalizationService>(), new JsonNetSerializer(), Mock.Of<ILocalizedTextService>(), Mock.Of<IShortStringHelper>());
_parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty<IManifestFilter>()), loggerFactory.CreateLogger<ManifestParser>(), loggerFactory, _ioHelper, TestHelper.GetHostingEnvironment(), Mock.Of<IDataTypeService>(), Mock.Of<ILocalizationService>(), new JsonNetSerializer(), Mock.Of<ILocalizedTextService>(), Mock.Of<IShortStringHelper>());
}
[Test]

View File

@@ -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");

View File

@@ -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<IPackageActionRunner>(),
//we don't want to extract package files to the real root, so extract to a test folder
Mock.Of<IHostingEnvironment>(x => x.ApplicationPhysicalPath == _testBaseFolder.FullName));

View File

@@ -52,7 +52,7 @@ namespace Umbraco.Tests.PublishedContent
var serializer = new ConfigurationEditorJsonSerializer();
var imageSourceParser = new HtmlImageSourceParser(publishedUrlProvider);
var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, loggerFactory.CreateLogger<RichTextEditorPastedImages>(), IOHelper, Mock.Of<IMediaService>(), Mock.Of<IContentTypeBaseServiceProvider>(), Mock.Of<IMediaFileSystem>(), ShortStringHelper, publishedUrlProvider, serializer);
var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, loggerFactory.CreateLogger<RichTextEditorPastedImages>(), HostingEnvironment, Mock.Of<IMediaService>(), Mock.Of<IContentTypeBaseServiceProvider>(), Mock.Of<IMediaFileSystem>(), ShortStringHelper, publishedUrlProvider, serializer);
var localLinkParser = new HtmlLocalLinkParser(umbracoContextAccessor, publishedUrlProvider);
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new RichTextPropertyEditor(

View File

@@ -57,7 +57,7 @@ namespace Umbraco.Tests.PublishedContent
var publishedUrlProvider = Mock.Of<IPublishedUrlProvider>();
var imageSourceParser = new HtmlImageSourceParser(publishedUrlProvider);
var serializer = new ConfigurationEditorJsonSerializer();
var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, loggerFactory.CreateLogger<RichTextEditorPastedImages>(), IOHelper, mediaService, contentTypeBaseServiceProvider, mediaFileService, ShortStringHelper, publishedUrlProvider, serializer);
var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, loggerFactory.CreateLogger<RichTextEditorPastedImages>(), HostingEnvironment, mediaService, contentTypeBaseServiceProvider, mediaFileService, ShortStringHelper, publishedUrlProvider, serializer);
var linkParser = new HtmlLocalLinkParser(umbracoContextAccessor, publishedUrlProvider);
var localizationService = Mock.Of<ILocalizationService>();

View File

@@ -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> 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;
}

View File

@@ -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> 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();

View File

@@ -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
/// <returns>The text output of the macro execution.</returns>
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);
}

View File

@@ -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<IUmbracoContext> _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;

View File

@@ -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<IIOHelper>();
var root = ioHelper.MapPath(rootVirtualPath);
var hostingEnvironment = Current.Factory.GetRequiredService<IHostingEnvironment>();
var root = hostingEnvironment.MapPathContentRoot(rootVirtualPath);
//ensure it exists
Directory.CreateDirectory(root);
var provider = new MultipartFormDataStreamProvider(root);

View File

@@ -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<ClientDependencyConfiguration> logger, IIOHelper ioHelper)
public ClientDependencyConfiguration(ILogger<ClientDependencyConfiguration> 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));
}
/// <summary>

View File

@@ -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<ClientDependencyRuntimeMinifier> _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<ClientDependencyRuntimeMinifier>();
_umbracoVersion = umbracoVersion;
@@ -109,7 +106,7 @@ namespace Umbraco.Web.WebAssets.CDF
public void Reset()
{
// Update ClientDependency version
var clientDependencyConfig = new ClientDependencyConfiguration(_loggerFactory.CreateLogger<ClientDependencyConfiguration>(), _ioHelper);
var clientDependencyConfig = new ClientDependencyConfiguration(_loggerFactory.CreateLogger<ClientDependencyConfiguration>(), _hostingEnvironment);
var clientDependencyUpdated = clientDependencyConfig.UpdateVersionNumber(
_umbracoVersion.SemanticVersion, DateTime.UtcNow, "yyyyMMdd");
// Delete ClientDependency temp directories to make sure we get fresh caches