From 04e04ae47a37da86724143a47491850e8caeaded Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 9 Oct 2017 14:40:23 +1100 Subject: [PATCH 1/6] Ensures that the local folder does not also get created when using the env temp storage location, this is also a tiny bit better for perfs --- src/Umbraco.Core/PluginManager.cs | 82 +++++++++++++++++++------------ 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/src/Umbraco.Core/PluginManager.cs b/src/Umbraco.Core/PluginManager.cs index 0489093712..8aa87f0ef8 100644 --- a/src/Umbraco.Core/PluginManager.cs +++ b/src/Umbraco.Core/PluginManager.cs @@ -41,7 +41,8 @@ namespace Umbraco.Core private readonly IServiceProvider _serviceProvider; private readonly IRuntimeCacheProvider _runtimeCache; private readonly ProfilingLogger _logger; - private readonly string _tempFolder; + private string _pluginListFilePath; + private string _pluginHashFilePath; private readonly object _typesLock = new object(); private readonly Dictionary _types = new Dictionary(); @@ -67,12 +68,7 @@ namespace Umbraco.Core _serviceProvider = serviceProvider; _runtimeCache = runtimeCache; _logger = logger; - - // the temp folder where the cache file lives - _tempFolder = IOHelper.MapPath("~/App_Data/TEMP/PluginCache"); - if (Directory.Exists(_tempFolder) == false) - Directory.CreateDirectory(_tempFolder); - + var pluginListFile = GetPluginListFilePath(); if (detectChanges) @@ -234,16 +230,8 @@ namespace Umbraco.Core /// private void WriteCachePluginsHash() { - var filePath = GetPluginHashFilePath(); - - // be absolutely sure the folder exists - var folder = Path.GetDirectoryName(filePath); - if (folder == null) - throw new InvalidOperationException("The folder could not be determined for the file " + filePath); - if (Directory.Exists(folder) == false) - Directory.CreateDirectory(folder); - - File.WriteAllText(filePath, CurrentAssembliesHash.ToString(), Encoding.UTF8); + var filePath = GetPluginHashFilePath(); + File.WriteAllText(filePath, CurrentAssembliesHash, Encoding.UTF8); } /// @@ -438,11 +426,18 @@ namespace Umbraco.Core } private string GetPluginListFilePath() - { + { + //if it's already set then return it - we don't care about locking here + //if 2 threads do this at the same time it won't hurt + if (_pluginListFilePath != null) + return _pluginListFilePath; + + string pluginListFilePath; switch (GlobalSettings.LocalTempStorageLocation) { case LocalTempStorage.AspNetTemp: - return Path.Combine(HttpRuntime.CodegenDir, @"UmbracoData\umbraco-plugins.list"); + pluginListFilePath = Path.Combine(HttpRuntime.CodegenDir, @"UmbracoData\umbraco-plugins.list"); + break; case LocalTempStorage.EnvironmentTemp: var appDomainHash = HttpRuntime.AppDomainAppId.ToSHA1(); var cachePath = Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "UmbracoData", @@ -450,19 +445,39 @@ namespace Umbraco.Core // to worker A again, in theory the %temp% folder should already be empty but we really want to make sure that its not // utilizing an old path appDomainHash); - return Path.Combine(cachePath, "umbraco-plugins.list"); + pluginListFilePath = Path.Combine(cachePath, "umbraco-plugins.list"); + break; case LocalTempStorage.Default: default: - return Path.Combine(_tempFolder, "umbraco-plugins." + NetworkHelper.FileSafeMachineName + ".list"); + var tempFolder = IOHelper.MapPath("~/App_Data/TEMP/PluginCache"); + pluginListFilePath = Path.Combine(tempFolder, "umbraco-plugins." + NetworkHelper.FileSafeMachineName + ".list"); + break; } + + //ensure the folder exists + var folder = Path.GetDirectoryName(pluginListFilePath); + if (folder == null) + throw new InvalidOperationException("The folder could not be determined for the file " + pluginListFilePath); + if (Directory.Exists(folder) == false) + Directory.CreateDirectory(folder); + + _pluginListFilePath = pluginListFilePath; + return _pluginListFilePath; } private string GetPluginHashFilePath() { + //if it's already set then return it - we don't care about locking here + //if 2 threads do this at the same time it won't hurt + if (_pluginHashFilePath != null) + return _pluginHashFilePath; + + string pluginHashFilePath; switch (GlobalSettings.LocalTempStorageLocation) { case LocalTempStorage.AspNetTemp: - return Path.Combine(HttpRuntime.CodegenDir, @"UmbracoData\umbraco-plugins.hash"); + pluginHashFilePath = Path.Combine(HttpRuntime.CodegenDir, @"UmbracoData\umbraco-plugins.hash"); + break; case LocalTempStorage.EnvironmentTemp: var appDomainHash = HttpRuntime.AppDomainAppId.ToSHA1(); var cachePath = Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "UmbracoData", @@ -470,23 +485,28 @@ namespace Umbraco.Core // to worker A again, in theory the %temp% folder should already be empty but we really want to make sure that its not // utilizing an old path appDomainHash); - return Path.Combine(cachePath, "umbraco-plugins.hash"); + pluginHashFilePath = Path.Combine(cachePath, "umbraco-plugins.hash"); + break; case LocalTempStorage.Default: default: - return Path.Combine(_tempFolder, "umbraco-plugins." + NetworkHelper.FileSafeMachineName + ".hash"); + pluginHashFilePath = Path.Combine(_pluginListFilePath, "umbraco-plugins." + NetworkHelper.FileSafeMachineName + ".hash"); + break; } + + //ensure the folder exists + var folder = Path.GetDirectoryName(pluginHashFilePath); + if (folder == null) + throw new InvalidOperationException("The folder could not be determined for the file " + pluginHashFilePath); + if (Directory.Exists(folder) == false) + Directory.CreateDirectory(folder); + + _pluginHashFilePath = pluginHashFilePath; + return _pluginHashFilePath; } internal void WriteCache() { var filePath = GetPluginListFilePath(); - - // be absolutely sure the folder exists - var folder = Path.GetDirectoryName(filePath); - if (folder == null) - throw new InvalidOperationException("The folder could not be determined for the file " + filePath); - if (Directory.Exists(folder) == false) - Directory.CreateDirectory(folder); using (var stream = GetFileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, ListFileOpenWriteTimeout)) using (var writer = new StreamWriter(stream)) From ce814163686d8e4736616cabb58c07371628c0ce Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 9 Oct 2017 14:50:34 +1100 Subject: [PATCH 2/6] Ensures the DistCache file is stored in the same configured temp location as the plugin cache files --- src/Umbraco.Core/PluginManager.cs | 3 +- .../Sync/DatabaseServerMessenger.cs | 51 ++++++++++++++++--- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Core/PluginManager.cs b/src/Umbraco.Core/PluginManager.cs index 8aa87f0ef8..e31e5752c1 100644 --- a/src/Umbraco.Core/PluginManager.cs +++ b/src/Umbraco.Core/PluginManager.cs @@ -489,7 +489,8 @@ namespace Umbraco.Core break; case LocalTempStorage.Default: default: - pluginHashFilePath = Path.Combine(_pluginListFilePath, "umbraco-plugins." + NetworkHelper.FileSafeMachineName + ".hash"); + var tempFolder = IOHelper.MapPath("~/App_Data/TEMP/PluginCache"); + pluginHashFilePath = Path.Combine(tempFolder, "umbraco-plugins." + NetworkHelper.FileSafeMachineName + ".hash"); break; } diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs index 12cb465b50..98c57e67df 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs @@ -14,6 +14,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence; using umbraco.interfaces; +using Umbraco.Core.Configuration; using Umbraco.Core.Persistence.SqlSyntax; namespace Umbraco.Core.Sync @@ -39,6 +40,7 @@ namespace Umbraco.Core.Sync private bool _syncing; private bool _released; private readonly ProfilingLogger _profilingLogger; + private string _distCacheFilePath; protected DatabaseServerMessengerOptions Options { get; private set; } protected ApplicationContext ApplicationContext { get { return _appContext; } } @@ -502,16 +504,51 @@ namespace Umbraco.Core.Sync /// Gets the sync file path for the local server. /// /// The sync file path for the local server. - private static string SyncFilePath + private string SyncFilePath { - get - { - var tempFolder = IOHelper.MapPath("~/App_Data/TEMP/DistCache/" + NetworkHelper.FileSafeMachineName); - if (Directory.Exists(tempFolder) == false) - Directory.CreateDirectory(tempFolder); + get { return GetDistCacheFilePath(); } + } - return Path.Combine(tempFolder, HttpRuntime.AppDomainAppId.ReplaceNonAlphanumericChars(string.Empty) + "-lastsynced.txt"); + private string GetDistCacheFilePath() + { + //if it's already set then return it - we don't care about locking here + //if 2 threads do this at the same time it won't hurt + if (_distCacheFilePath != null) + return _distCacheFilePath; + + var fileName = HttpRuntime.AppDomainAppId.ReplaceNonAlphanumericChars(string.Empty) + "-lastsynced.txt"; + + string distCacheFilePath; + switch (GlobalSettings.LocalTempStorageLocation) + { + case LocalTempStorage.AspNetTemp: + distCacheFilePath = Path.Combine(HttpRuntime.CodegenDir, @"UmbracoData", fileName); + break; + case LocalTempStorage.EnvironmentTemp: + var appDomainHash = HttpRuntime.AppDomainAppId.ToSHA1(); + var cachePath = Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "UmbracoData", + //include the appdomain hash is just a safety check, for example if a website is moved from worker A to worker B and then back + // to worker A again, in theory the %temp% folder should already be empty but we really want to make sure that its not + // utilizing an old path + appDomainHash); + distCacheFilePath = Path.Combine(cachePath, fileName); + break; + case LocalTempStorage.Default: + default: + var tempFolder = IOHelper.MapPath("~/App_Data/TEMP/DistCache"); + distCacheFilePath = Path.Combine(tempFolder, fileName); + break; } + + //ensure the folder exists + var folder = Path.GetDirectoryName(distCacheFilePath); + if (folder == null) + throw new InvalidOperationException("The folder could not be determined for the file " + distCacheFilePath); + if (Directory.Exists(folder) == false) + Directory.CreateDirectory(folder); + + _distCacheFilePath = distCacheFilePath; + return _distCacheFilePath; } #endregion From 422219ab21bfaa627ef6ec779cdf4bbfe4911344 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 9 Oct 2017 16:01:22 +1100 Subject: [PATCH 3/6] Updates the cache file paths to be resolved behind a lazy so that there's proper locking in place for accessing the value, this also makes the code a little nicer. --- src/Umbraco.Core/PluginManager.cs | 78 +++++++------------ .../Sync/DatabaseServerMessenger.cs | 28 ++----- 2 files changed, 34 insertions(+), 72 deletions(-) diff --git a/src/Umbraco.Core/PluginManager.cs b/src/Umbraco.Core/PluginManager.cs index e31e5752c1..aafbc92b8b 100644 --- a/src/Umbraco.Core/PluginManager.cs +++ b/src/Umbraco.Core/PluginManager.cs @@ -41,8 +41,8 @@ namespace Umbraco.Core private readonly IServiceProvider _serviceProvider; private readonly IRuntimeCacheProvider _runtimeCache; private readonly ProfilingLogger _logger; - private string _pluginListFilePath; - private string _pluginHashFilePath; + private readonly Lazy _pluginListFilePath = new Lazy(GetPluginListFilePath); + private readonly Lazy _pluginHashFilePath = new Lazy(GetPluginHashFilePath); private readonly object _typesLock = new object(); private readonly Dictionary _types = new Dictionary(); @@ -69,8 +69,6 @@ namespace Umbraco.Core _runtimeCache = runtimeCache; _logger = logger; - var pluginListFile = GetPluginListFilePath(); - if (detectChanges) { //first check if the cached hash is string.Empty, if it is then we need @@ -82,8 +80,8 @@ namespace Umbraco.Core // if the hash has changed, clear out the persisted list no matter what, this will force // rescanning of all plugin types including lazy ones. // http://issues.umbraco.org/issue/U4-4789 - if(File.Exists(pluginListFile)) - File.Delete(pluginListFile); + if(File.Exists(_pluginListFilePath.Value)) + File.Delete(_pluginListFilePath.Value); WriteCachePluginsHash(); } @@ -93,8 +91,8 @@ namespace Umbraco.Core // if the hash has changed, clear out the persisted list no matter what, this will force // rescanning of all plugin types including lazy ones. // http://issues.umbraco.org/issue/U4-4789 - if (File.Exists(pluginListFile)) - File.Delete(pluginListFile); + if (File.Exists(_pluginListFilePath.Value)) + File.Delete(_pluginListFilePath.Value); // always set to true if we're not detecting (generally only for testing) RequiresRescanning = true; @@ -187,11 +185,10 @@ namespace Umbraco.Core { if (_cachedAssembliesHash != null) return _cachedAssembliesHash; + + if (File.Exists(_pluginHashFilePath.Value) == false) return string.Empty; - var filePath = GetPluginHashFilePath(); - if (File.Exists(filePath) == false) return string.Empty; - - var hash = File.ReadAllText(filePath, Encoding.UTF8); + var hash = File.ReadAllText(_pluginHashFilePath.Value, Encoding.UTF8); _cachedAssembliesHash = hash; return _cachedAssembliesHash; @@ -229,9 +226,8 @@ namespace Umbraco.Core /// Writes the assembly hash file. /// private void WriteCachePluginsHash() - { - var filePath = GetPluginHashFilePath(); - File.WriteAllText(filePath, CurrentAssembliesHash, Encoding.UTF8); + { + File.WriteAllText(_pluginHashFilePath.Value, CurrentAssembliesHash, Encoding.UTF8); } /// @@ -351,8 +347,7 @@ namespace Umbraco.Core { try { - var filePath = GetPluginListFilePath(); - File.Delete(filePath); + File.Delete(_pluginListFilePath.Value); } catch { @@ -366,12 +361,11 @@ namespace Umbraco.Core internal Dictionary, IEnumerable> ReadCache() { var cache = new Dictionary, IEnumerable>(); - - var filePath = GetPluginListFilePath(); - if (File.Exists(filePath) == false) + + if (File.Exists(_pluginListFilePath.Value) == false) return cache; - using (var stream = GetFileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, ListFileOpenReadTimeout)) + using (var stream = GetFileStream(_pluginListFilePath.Value, FileMode.Open, FileAccess.Read, FileShare.Read, ListFileOpenReadTimeout)) using (var reader = new StreamReader(stream)) { while (true) @@ -414,24 +408,17 @@ namespace Umbraco.Core /// Generally only used for resetting cache, for example during the install process. public void ClearPluginCache() { - var path = GetPluginListFilePath(); - if (File.Exists(path)) - File.Delete(path); - - path = GetPluginHashFilePath(); - if (File.Exists(path)) - File.Delete(path); + if (File.Exists(_pluginListFilePath.Value)) + File.Delete(_pluginListFilePath.Value); + + if (File.Exists(_pluginHashFilePath.Value)) + File.Delete(_pluginHashFilePath.Value); _runtimeCache.ClearCacheItem(CacheKey); } - private string GetPluginListFilePath() - { - //if it's already set then return it - we don't care about locking here - //if 2 threads do this at the same time it won't hurt - if (_pluginListFilePath != null) - return _pluginListFilePath; - + private static string GetPluginListFilePath() + { string pluginListFilePath; switch (GlobalSettings.LocalTempStorageLocation) { @@ -461,17 +448,11 @@ namespace Umbraco.Core if (Directory.Exists(folder) == false) Directory.CreateDirectory(folder); - _pluginListFilePath = pluginListFilePath; - return _pluginListFilePath; + return pluginListFilePath; } - private string GetPluginHashFilePath() + private static string GetPluginHashFilePath() { - //if it's already set then return it - we don't care about locking here - //if 2 threads do this at the same time it won't hurt - if (_pluginHashFilePath != null) - return _pluginHashFilePath; - string pluginHashFilePath; switch (GlobalSettings.LocalTempStorageLocation) { @@ -500,16 +481,13 @@ namespace Umbraco.Core throw new InvalidOperationException("The folder could not be determined for the file " + pluginHashFilePath); if (Directory.Exists(folder) == false) Directory.CreateDirectory(folder); - - _pluginHashFilePath = pluginHashFilePath; - return _pluginHashFilePath; + + return pluginHashFilePath; } internal void WriteCache() { - var filePath = GetPluginListFilePath(); - - using (var stream = GetFileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, ListFileOpenWriteTimeout)) + using (var stream = GetFileStream(_pluginListFilePath.Value, FileMode.Create, FileAccess.Write, FileShare.None, ListFileOpenWriteTimeout)) using (var writer = new StreamWriter(stream)) { foreach (var typeList in _types.Values) @@ -755,7 +733,7 @@ namespace Umbraco.Core // else proceed, typeList = new TypeList(baseType, attributeType); - var scan = RequiresRescanning || File.Exists(GetPluginListFilePath()) == false; + var scan = RequiresRescanning || File.Exists(_pluginListFilePath.Value) == false; if (scan) { diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs index 98c57e67df..8d0fb54b1e 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs @@ -40,7 +40,7 @@ namespace Umbraco.Core.Sync private bool _syncing; private bool _released; private readonly ProfilingLogger _profilingLogger; - private string _distCacheFilePath; + private Lazy _distCacheFilePath = new Lazy(GetDistCacheFilePath); protected DatabaseServerMessengerOptions Options { get; private set; } protected ApplicationContext ApplicationContext { get { return _appContext; } } @@ -462,10 +462,9 @@ namespace Umbraco.Core.Sync /// private void ReadLastSynced() { - var path = SyncFilePath; - if (File.Exists(path) == false) return; + if (File.Exists(_distCacheFilePath.Value) == false) return; - var content = File.ReadAllText(path); + var content = File.ReadAllText(_distCacheFilePath.Value); int last; if (int.TryParse(content, out last)) _lastId = last; @@ -480,7 +479,7 @@ namespace Umbraco.Core.Sync /// private void SaveLastSynced(int id) { - File.WriteAllText(SyncFilePath, id.ToString(CultureInfo.InvariantCulture)); + File.WriteAllText(_distCacheFilePath.Value, id.ToString(CultureInfo.InvariantCulture)); _lastId = id; } @@ -500,22 +499,8 @@ namespace Umbraco.Core.Sync + "/D" + AppDomain.CurrentDomain.Id // eg 22 + "] " + Guid.NewGuid().ToString("N").ToUpper(); // make it truly unique - /// - /// Gets the sync file path for the local server. - /// - /// The sync file path for the local server. - private string SyncFilePath + private static string GetDistCacheFilePath() { - get { return GetDistCacheFilePath(); } - } - - private string GetDistCacheFilePath() - { - //if it's already set then return it - we don't care about locking here - //if 2 threads do this at the same time it won't hurt - if (_distCacheFilePath != null) - return _distCacheFilePath; - var fileName = HttpRuntime.AppDomainAppId.ReplaceNonAlphanumericChars(string.Empty) + "-lastsynced.txt"; string distCacheFilePath; @@ -547,8 +532,7 @@ namespace Umbraco.Core.Sync if (Directory.Exists(folder) == false) Directory.CreateDirectory(folder); - _distCacheFilePath = distCacheFilePath; - return _distCacheFilePath; + return distCacheFilePath; } #endregion From 7f44f4a0300eb5f872ff6c4c0a7761d95f6f0d3a Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 9 Oct 2017 16:01:49 +1100 Subject: [PATCH 4/6] readonly field --- src/Umbraco.Core/Sync/DatabaseServerMessenger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs index 8d0fb54b1e..6f1fc03281 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs @@ -40,7 +40,7 @@ namespace Umbraco.Core.Sync private bool _syncing; private bool _released; private readonly ProfilingLogger _profilingLogger; - private Lazy _distCacheFilePath = new Lazy(GetDistCacheFilePath); + private readonly Lazy _distCacheFilePath = new Lazy(GetDistCacheFilePath); protected DatabaseServerMessengerOptions Options { get; private set; } protected ApplicationContext ApplicationContext { get { return _appContext; } } From fbda4fc8d175cd7549a76007c704bec21d37582a Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 9 Oct 2017 17:49:01 +1100 Subject: [PATCH 5/6] Fixes part of the failing tests --- src/Umbraco.Tests/Models/ContentTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Tests/Models/ContentTests.cs b/src/Umbraco.Tests/Models/ContentTests.cs index 4244188697..aa9fc35524 100644 --- a/src/Umbraco.Tests/Models/ContentTests.cs +++ b/src/Umbraco.Tests/Models/ContentTests.cs @@ -20,7 +20,7 @@ using Umbraco.Tests.TestHelpers.Entities; namespace Umbraco.Tests.Models { [TestFixture] - public class ContentTests : BaseUmbracoConfigurationTest + public class ContentTests : BaseUmbracoApplicationTest { [SetUp] public void Init() From 4b08c3a5c371a28cff2a0c451a9ac7c89cd365dc Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 9 Oct 2017 18:20:07 +1100 Subject: [PATCH 6/6] Reset PluginManager on each tests, no reason not to, this should resolve the issue --- src/Umbraco.Core/PluginManager.cs | 35 +++++++------- .../TestHelpers/BaseUmbracoApplicationTest.cs | 48 +++++++------------ 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/Umbraco.Core/PluginManager.cs b/src/Umbraco.Core/PluginManager.cs index aafbc92b8b..aa318de287 100644 --- a/src/Umbraco.Core/PluginManager.cs +++ b/src/Umbraco.Core/PluginManager.cs @@ -76,22 +76,22 @@ namespace Umbraco.Core RequiresRescanning = (CachedAssembliesHash != CurrentAssembliesHash) || CachedAssembliesHash == string.Empty; //if they have changed, we need to write the new file if (RequiresRescanning) - { - // if the hash has changed, clear out the persisted list no matter what, this will force - // rescanning of all plugin types including lazy ones. - // http://issues.umbraco.org/issue/U4-4789 - if(File.Exists(_pluginListFilePath.Value)) + { + // if the hash has changed, clear out the persisted list no matter what, this will force + // rescanning of all plugin types including lazy ones. + // http://issues.umbraco.org/issue/U4-4789 + if(File.Exists(_pluginListFilePath.Value)) File.Delete(_pluginListFilePath.Value); WriteCachePluginsHash(); } } else - { - // if the hash has changed, clear out the persisted list no matter what, this will force - // rescanning of all plugin types including lazy ones. + { + // if the hash has changed, clear out the persisted list no matter what, this will force + // rescanning of all plugin types including lazy ones. // http://issues.umbraco.org/issue/U4-4789 - if (File.Exists(_pluginListFilePath.Value)) + if (File.Exists(_pluginListFilePath.Value)) File.Delete(_pluginListFilePath.Value); // always set to true if we're not detecting (generally only for testing) @@ -270,7 +270,7 @@ namespace Umbraco.Core } } } - return generator.GenerateHash(); + return generator.GenerateHash(); } } } @@ -310,7 +310,7 @@ namespace Umbraco.Core uniqInfos.Add(fileOrFolder.FullName); generator.AddFileSystemItem(fileOrFolder); } - return generator.GenerateHash(); + return generator.GenerateHash(); } } } @@ -343,7 +343,7 @@ namespace Umbraco.Core { return ReadCache(); } - catch + catch (Exception ex) { try { @@ -440,7 +440,7 @@ namespace Umbraco.Core pluginListFilePath = Path.Combine(tempFolder, "umbraco-plugins." + NetworkHelper.FileSafeMachineName + ".list"); break; } - + //ensure the folder exists var folder = Path.GetDirectoryName(pluginListFilePath); if (folder == null) @@ -503,8 +503,7 @@ namespace Umbraco.Core internal void UpdateCache() { - // note - // at the moment we write the cache to disk every time we update it. ideally we defer the writing + // TODO: at the moment we write the cache to disk every time we update it. ideally we defer the writing // since all the updates are going to happen in a row when Umbraco starts. that being said, the // file is small enough, so it is not a priority. WriteCache(); @@ -517,13 +516,13 @@ namespace Umbraco.Core while (true) { try - { + { return new FileStream(path, fileMode, fileAccess, fileShare); } - catch + catch (Exception ex) { if (--attempts == 0) - throw; + throw; LogHelper.Debug(string.Format("Attempted to get filestream for file {0} failed, {1} attempts left, pausing for {2} milliseconds", path, attempts, pauseMilliseconds)); Thread.Sleep(pauseMilliseconds); diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index 49895ed453..6444638928 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -118,25 +118,12 @@ namespace Umbraco.Tests.TestHelpers }); } - /// - /// By default this returns false which means the plugin manager will not be reset so it doesn't need to re-scan - /// all of the assemblies. Inheritors can override this if plugin manager resetting is required, generally needs - /// to be set to true if the SetupPluginManager has been overridden. - /// - protected virtual bool PluginManagerResetRequired - { - get { return false; } - } - /// /// Inheritors can resset the plugin manager if they choose to on teardown /// protected virtual void ResetPluginManager() { - if (PluginManagerResetRequired) - { - PluginManager.Current = null; - } + PluginManager.Current = null; } protected virtual CacheHelper CreateCacheHelper() @@ -185,26 +172,23 @@ namespace Umbraco.Tests.TestHelpers /// protected virtual void SetupPluginManager() { - if (PluginManager.Current == null || PluginManagerResetRequired) + PluginManager.Current = new PluginManager( + new ActivatorServiceProvider(), + CacheHelper.RuntimeCache, ProfilingLogger, false) { - PluginManager.Current = new PluginManager( - new ActivatorServiceProvider(), - CacheHelper.RuntimeCache, ProfilingLogger, false) + AssembliesToScan = new[] { - AssembliesToScan = new[] - { - Assembly.Load("Umbraco.Core"), - Assembly.Load("umbraco"), - Assembly.Load("Umbraco.Tests"), - Assembly.Load("businesslogic"), - Assembly.Load("cms"), - Assembly.Load("controls"), - Assembly.Load("umbraco.editorControls"), - Assembly.Load("umbraco.MacroEngines"), - Assembly.Load("umbraco.providers"), - } - }; - } + Assembly.Load("Umbraco.Core"), + Assembly.Load("umbraco"), + Assembly.Load("Umbraco.Tests"), + Assembly.Load("businesslogic"), + Assembly.Load("cms"), + Assembly.Load("controls"), + Assembly.Load("umbraco.editorControls"), + Assembly.Load("umbraco.MacroEngines"), + Assembly.Load("umbraco.providers"), + } + }; } ///