diff --git a/src/Umbraco.Core/NetworkHelper.cs b/src/Umbraco.Core/NetworkHelper.cs new file mode 100644 index 0000000000..d69c4a963c --- /dev/null +++ b/src/Umbraco.Core/NetworkHelper.cs @@ -0,0 +1,50 @@ +using System; + +namespace Umbraco.Core +{ + /// + /// Currently just used to get the machine name in med trust and to format a machine name for use with file names + /// + internal class NetworkHelper + { + /// + /// Returns the machine name that is safe to use in file paths. + /// + /// + /// see: https://github.com/Shandem/ClientDependency/issues/4 + /// + public static string FileSafeMachineName + { + get { return MachineName.ReplaceNonAlphanumericChars('-'); } + } + + /// + /// Returns the current machine name + /// + /// + /// Tries to resolve the machine name, if it cannot it uses the config section. + /// + 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()"); + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/PluginManager.cs b/src/Umbraco.Core/PluginManager.cs index 24c7070498..a12add664b 100644 --- a/src/Umbraco.Core/PluginManager.cs +++ b/src/Umbraco.Core/PluginManager.cs @@ -20,7 +20,6 @@ using File = System.IO.File; namespace Umbraco.Core { - /// /// Used to resolve all plugin types and cache them and is also used to instantiate plugin types /// @@ -307,15 +306,15 @@ namespace Umbraco.Core _appContext.ApplicationCache.ClearCacheItem("umbraco-plugins.list"); } } - + 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() { - return Path.Combine(_tempFolder, "umbraco-plugins.hash"); + return Path.Combine(_tempFolder, string.Format("umbraco-plugins.{0}.hash", NetworkHelper.FileSafeMachineName)); } /// diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs index df7c0d07b0..87b4c676b5 100644 --- a/src/Umbraco.Core/StringExtensions.cs +++ b/src/Umbraco.Core/StringExtensions.cs @@ -28,6 +28,17 @@ namespace Umbraco.Core [UmbracoWillObsolete("Do not use this constants. See IShortStringHelper.CleanStringForSafeAliasJavaScriptCode.")] 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 toExclude) { var sb = new StringBuilder(str.Length); diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 405cf23025..4d5bd09932 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -238,6 +238,7 @@ +