Fixes: U4-2627 Ensure that the plugins cache files are named with the machine name

This commit is contained in:
Shannon
2013-08-16 12:25:38 +10:00
parent d0a9e3236e
commit 973b466798
4 changed files with 65 additions and 4 deletions

View File

@@ -0,0 +1,50 @@
using System;
namespace Umbraco.Core
{
/// <summary>
/// Currently just used to get the machine name in med trust and to format a machine name for use with file names
/// </summary>
internal class NetworkHelper
{
/// <summary>
/// Returns the machine name that is safe to use in file paths.
/// </summary>
/// <remarks>
/// see: https://github.com/Shandem/ClientDependency/issues/4
/// </remarks>
public static string FileSafeMachineName
{
get { return MachineName.ReplaceNonAlphanumericChars('-'); }
}
/// <summary>
/// Returns the current machine name
/// </summary>
/// <remarks>
/// Tries to resolve the machine name, if it cannot it uses the config section.
/// </remarks>
public static string MachineName
{
get
{
try
{
return Environment.MachineName;
}
catch
{
try
{
return System.Net.Dns.GetHostName();
}
catch
{
//if we get here it means we cannot access the machine name
throw new ApplicationException("Cannot resolve the current machine name eithe by Environment.MachineName or by Dns.GetHostname()");
}
}
}
}
}
}

View File

@@ -20,7 +20,6 @@ using File = System.IO.File;
namespace Umbraco.Core namespace Umbraco.Core
{ {
/// <summary> /// <summary>
/// Used to resolve all plugin types and cache them and is also used to instantiate plugin types /// Used to resolve all plugin types and cache them and is also used to instantiate plugin types
/// </summary> /// </summary>
@@ -307,15 +306,15 @@ namespace Umbraco.Core
_appContext.ApplicationCache.ClearCacheItem("umbraco-plugins.list"); _appContext.ApplicationCache.ClearCacheItem("umbraco-plugins.list");
} }
} }
private string GetPluginListFilePath() private string GetPluginListFilePath()
{ {
return Path.Combine(_tempFolder, "umbraco-plugins.list"); return Path.Combine(_tempFolder, string.Format("umbraco-plugins.{0}.list", NetworkHelper.FileSafeMachineName));
} }
private string GetPluginHashFilePath() private string GetPluginHashFilePath()
{ {
return Path.Combine(_tempFolder, "umbraco-plugins.hash"); return Path.Combine(_tempFolder, string.Format("umbraco-plugins.{0}.hash", NetworkHelper.FileSafeMachineName));
} }
/// <summary> /// <summary>

View File

@@ -28,6 +28,17 @@ namespace Umbraco.Core
[UmbracoWillObsolete("Do not use this constants. See IShortStringHelper.CleanStringForSafeAliasJavaScriptCode.")] [UmbracoWillObsolete("Do not use this constants. See IShortStringHelper.CleanStringForSafeAliasJavaScriptCode.")]
public const string UmbracoInvalidFirstCharacters = "01234567890"; public const string UmbracoInvalidFirstCharacters = "01234567890";
internal static string ReplaceNonAlphanumericChars(this string input, char replacement)
{
//any character that is not alphanumeric, convert to a hyphen
var mName = input;
foreach (var c in mName.ToCharArray().Where(c => !char.IsLetterOrDigit(c)))
{
mName = mName.Replace(c, replacement);
}
return mName;
}
public static string ExceptChars(this string str, HashSet<char> toExclude) public static string ExceptChars(this string str, HashSet<char> toExclude)
{ {
var sb = new StringBuilder(str.Length); var sb = new StringBuilder(str.Length);

View File

@@ -238,6 +238,7 @@
<Compile Include="Models\UmbracoEntity.cs" /> <Compile Include="Models\UmbracoEntity.cs" />
<Compile Include="Models\UmbracoObjectTypes.cs" /> <Compile Include="Models\UmbracoObjectTypes.cs" />
<Compile Include="Models\UmbracoObjectTypesExtensions.cs" /> <Compile Include="Models\UmbracoObjectTypesExtensions.cs" />
<Compile Include="NetworkHelper.cs" />
<Compile Include="ObjectResolution\ApplicationEventsResolver.cs" /> <Compile Include="ObjectResolution\ApplicationEventsResolver.cs" />
<Compile Include="ObjectResolution\ResolverCollection.cs" /> <Compile Include="ObjectResolution\ResolverCollection.cs" />
<Compile Include="Persistence\Caching\InMemoryCacheProvider.cs" /> <Compile Include="Persistence\Caching\InMemoryCacheProvider.cs" />