diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs index 778e40d613..33bd83fb26 100644 --- a/src/Umbraco.Core/StringExtensions.cs +++ b/src/Umbraco.Core/StringExtensions.cs @@ -101,6 +101,17 @@ namespace Umbraco.Core } } + internal static string ReplaceNonAlphanumericChars(this string input, string 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.ToString(CultureInfo.InvariantCulture), replacement); + } + return mName; + } + internal static string ReplaceNonAlphanumericChars(this string input, char replacement) { //any character that is not alphanumeric, convert to a hyphen diff --git a/src/UmbracoExamine/ExamineHelper.cs b/src/UmbracoExamine/ExamineHelper.cs index 21141835ce..0241c5b068 100644 --- a/src/UmbracoExamine/ExamineHelper.cs +++ b/src/UmbracoExamine/ExamineHelper.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Web; using Examine; using Examine.LuceneEngine.Config; using Umbraco.Core; @@ -22,7 +23,10 @@ namespace UmbracoExamine { var indexSet = GetConfiguredIndexSet(name, config, matchingVerb, alreadyConfiguredCheck); if (indexSet == null) return; - indexSet.IndexPath = indexSet.IndexPath.Replace("{machinename}", NetworkHelper.FileSafeMachineName).EnsureEndsWith('/'); + indexSet.IndexPath = indexSet.IndexPath + .Replace("{machinename}", NetworkHelper.FileSafeMachineName) + .Replace("{appdomainappid}", HttpRuntime.AppDomainAppId.ReplaceNonAlphanumericChars("")) + .EnsureEndsWith('/'); } public static IndexSet GetConfiguredIndexSet(string name, System.Collections.Specialized.NameValueCollection config, string matchingVerb, Func alreadyConfiguredCheck) diff --git a/src/UmbracoExamine/LocalStorage/LocalTempStorageIndexer.cs b/src/UmbracoExamine/LocalStorage/LocalTempStorageIndexer.cs index 4639b006db..c4a7e170a8 100644 --- a/src/UmbracoExamine/LocalStorage/LocalTempStorageIndexer.cs +++ b/src/UmbracoExamine/LocalStorage/LocalTempStorageIndexer.cs @@ -16,11 +16,13 @@ namespace UmbracoExamine.LocalStorage { internal class LocalTempStorageIndexer { - private string _tempPath; public Lucene.Net.Store.Directory LuceneDirectory { get; private set; } private readonly object _locker = new object(); public SnapshotDeletionPolicy Snapshotter { get; private set; } + public string TempPath { get; private set; } + + public LocalTempStorageIndexer() { IndexDeletionPolicy policy = new KeepOnlyLastCommitDeletionPolicy(); @@ -31,7 +33,7 @@ namespace UmbracoExamine.LocalStorage { var codegenPath = HttpRuntime.CodegenDir; - _tempPath = Path.Combine(codegenPath, configuredPath.TrimStart('~', '/').Replace("/", "\\")); + TempPath = Path.Combine(codegenPath, configuredPath.TrimStart('~', '/').Replace("/", "\\")); switch (localStorageType) { @@ -40,18 +42,18 @@ namespace UmbracoExamine.LocalStorage //create the custom lucene directory which will keep the main and temp FS's in sync LuceneDirectory = LocalTempStorageDirectoryTracker.Current.GetDirectory( - new DirectoryInfo(_tempPath), + new DirectoryInfo(TempPath), baseLuceneDirectory, //flag to disable the mirrored folder if not successful success == false); break; case LocalStorageType.LocalOnly: - if (Directory.Exists(_tempPath) == false) + if (Directory.Exists(TempPath) == false) { - Directory.CreateDirectory(_tempPath); + Directory.CreateDirectory(TempPath); } - LuceneDirectory = DirectoryTracker.Current.GetDirectory(new DirectoryInfo(_tempPath)); + LuceneDirectory = DirectoryTracker.Current.GetDirectory(new DirectoryInfo(TempPath)); break; default: throw new ArgumentOutOfRangeException("localStorageType"); @@ -63,9 +65,9 @@ namespace UmbracoExamine.LocalStorage { lock (_locker) { - if (Directory.Exists(_tempPath) == false) + if (Directory.Exists(TempPath) == false) { - Directory.CreateDirectory(_tempPath); + Directory.CreateDirectory(TempPath); } //copy index if it exists, don't do anything if it's not there @@ -93,7 +95,7 @@ namespace UmbracoExamine.LocalStorage .Distinct() .ToArray(); - var tempDir = new DirectoryInfo(_tempPath); + var tempDir = new DirectoryInfo(TempPath); //Get all files in the temp storage that don't exist in the snapshot collection, we want to remove these var toRemove = tempDir.GetFiles() @@ -111,7 +113,7 @@ namespace UmbracoExamine.LocalStorage { try { - File.Delete(Path.Combine(_tempPath, file)); + File.Delete(Path.Combine(TempPath, file)); } catch (IOException ex) { @@ -132,7 +134,7 @@ namespace UmbracoExamine.LocalStorage foreach (var fileName in allSnapshotFiles.Where(f => f.IsNullOrWhiteSpace() == false)) { - var destination = Path.Combine(_tempPath, Path.GetFileName(fileName)); + var destination = Path.Combine(TempPath, Path.GetFileName(fileName)); //don't copy if it's already there, lucene is 'write once' so this file is meant to be there already if (File.Exists(destination)) continue;