Fix issue with NuCache knowing the web project

This commit is contained in:
Bjarke Berg
2020-02-20 09:05:42 +01:00
parent 46a68d1b86
commit bbe9aa1848
4 changed files with 42 additions and 32 deletions

View File

@@ -0,0 +1,39 @@
using System;
using System.IO;
using Umbraco.Core.IO;
namespace Umbraco.Web.Install
{
public class FilePermissionDirectoryHelper
{
// tries to create a file
// if successful, the file is deleted
// creates the directory if needed - does not delete it
public static bool TryCreateDirectory(string dir, IIOHelper ioHelper)
{
try
{
var dirPath = ioHelper.MapPath(dir);
if (Directory.Exists(dirPath) == false)
Directory.CreateDirectory(dirPath);
var filePath = dirPath + "/" + CreateRandomFileName() + ".tmp";
File.WriteAllText(filePath, "This is an Umbraco internal test file. It is safe to delete it.");
File.Delete(filePath);
return true;
}
catch
{
return false;
}
}
public static string CreateRandomFileName()
{
return "umbraco-test." + Guid.NewGuid().ToString("N").Substring(0, 8);
}
}
}

View File

@@ -364,7 +364,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
public override bool EnsureEnvironment(out IEnumerable<string> errors)
{
// must have app_data and be able to write files into it
var ok = FilePermissionHelper.TryCreateDirectory(GetLocalFilesPath(), _ioHelper);
var ok = FilePermissionDirectoryHelper.TryCreateDirectory(GetLocalFilesPath(), _ioHelper);
errors = ok ? Enumerable.Empty<string>() : new[] { "NuCache local files." };
return ok;
}

View File

@@ -13,7 +13,6 @@
<ItemGroup>
<ProjectReference Include="..\Umbraco.Abstractions\Umbraco.Abstractions.csproj" />
<ProjectReference Include="..\Umbraco.Infrastructure\Umbraco.Infrastructure.csproj" />
<ProjectReference Include="..\Umbraco.Web\Umbraco.Web.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -141,7 +141,7 @@ namespace Umbraco.Web.Install
{
try
{
var path = _ioHelper.MapPath(dir + "/" + CreateRandomName());
var path = _ioHelper.MapPath(dir + "/" + FilePermissionDirectoryHelper.CreateRandomFileName());
Directory.CreateDirectory(path);
Directory.Delete(path);
return true;
@@ -152,29 +152,6 @@ namespace Umbraco.Web.Install
}
}
// tries to create a file
// if successful, the file is deleted
// creates the directory if needed - does not delete it
public static bool TryCreateDirectory(string dir, IIOHelper ioHelper)
{
try
{
var dirPath = ioHelper.MapPath(dir);
if (Directory.Exists(dirPath) == false)
Directory.CreateDirectory(dirPath);
var filePath = dirPath + "/" + CreateRandomName() + ".tmp";
File.WriteAllText(filePath, "This is an Umbraco internal test file. It is safe to delete it.");
File.Delete(filePath);
return true;
}
catch
{
return false;
}
}
// tries to create a file
// if successful, the file is deleted
//
@@ -194,7 +171,7 @@ namespace Umbraco.Web.Install
if (canWrite)
{
var filePath = dirPath + "/" + CreateRandomName() + ".tmp";
var filePath = dirPath + "/" + FilePermissionDirectoryHelper.CreateRandomFileName() + ".tmp";
File.WriteAllText(filePath, "This is an Umbraco internal test file. It is safe to delete it.");
File.Delete(filePath);
return true;
@@ -261,10 +238,5 @@ namespace Umbraco.Web.Install
return false;
}
}
private static string CreateRandomName()
{
return "umbraco-test." + Guid.NewGuid().ToString("N").Substring(0, 8);
}
}
}