From 0011d568c6bee2d155c6268aa935d4889e9eac89 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Wed, 21 Nov 2012 08:28:11 +0500 Subject: [PATCH] Fixes up HashCodeCombiner with correct long field intead of int with correct initialization. Adds App_Code and global.asax to be monitored for changes to create the hash code. --- src/Umbraco.Core/HashCodeCombiner.cs | 42 ++++++++++++++++++---------- src/Umbraco.Core/PluginManager.cs | 28 +++++++++++++------ 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/Umbraco.Core/HashCodeCombiner.cs b/src/Umbraco.Core/HashCodeCombiner.cs index 78f5eb6839..be640d7cbf 100644 --- a/src/Umbraco.Core/HashCodeCombiner.cs +++ b/src/Umbraco.Core/HashCodeCombiner.cs @@ -17,7 +17,7 @@ namespace Umbraco.Core /// internal class HashCodeCombiner { - private int _combinedHash; + private long _combinedHash = 5381L; internal void AddInt(int i) { @@ -40,27 +40,41 @@ namespace Umbraco.Core AddInt((StringComparer.InvariantCultureIgnoreCase).GetHashCode(s)); } - internal void AddFile(FileInfo f) + internal void AddFileSystemItem(FileSystemInfo f) { AddCaseInsensitiveString(f.FullName); AddDateTime(f.CreationTimeUtc); AddDateTime(f.LastWriteTimeUtc); - AddInt(f.Length.GetHashCode()); + + //check if it is a file or folder + var fileInfo = f as FileInfo; + if (fileInfo != null) + { + AddInt(fileInfo.Length.GetHashCode()); + } + + var dirInfo = f as DirectoryInfo; + if (dirInfo != null) + { + foreach (var d in dirInfo.GetFiles()) + { + AddFile(d); + } + foreach (var s in dirInfo.GetDirectories()) + { + AddFolder(s); + } + } + } + + internal void AddFile(FileInfo f) + { + AddFileSystemItem(f); } internal void AddFolder(DirectoryInfo d) { - AddCaseInsensitiveString(d.FullName); - AddDateTime(d.CreationTimeUtc); - AddDateTime(d.LastWriteTimeUtc); - foreach (var f in d.GetFiles()) - { - AddFile(f); - } - foreach (var s in d.GetDirectories()) - { - AddFolder(s); - } + AddFileSystemItem(d); } /// diff --git a/src/Umbraco.Core/PluginManager.cs b/src/Umbraco.Core/PluginManager.cs index 1a43139632..e40b90fb64 100644 --- a/src/Umbraco.Core/PluginManager.cs +++ b/src/Umbraco.Core/PluginManager.cs @@ -53,11 +53,11 @@ namespace Umbraco.Core /// /// Creates a new PluginManager /// - /// + /// /// If true will detect changes in the /bin folder and therefor load plugins from the /// cached plugins file if one is found. If false will never use the cache file for plugins /// - internal PluginManager(bool detectBinChanges = true) + internal PluginManager(bool detectCodeChanges = true) { _tempFolder = IOHelper.MapPath("~/App_Data/TEMP/PluginCache"); //create the folder if it doesn't exist @@ -66,7 +66,7 @@ namespace Umbraco.Core Directory.CreateDirectory(_tempFolder); } - if (detectBinChanges) + if (detectCodeChanges) { //first check if the cached hash is 0, if it is then we ne //do the check if they've changed @@ -161,7 +161,17 @@ namespace Umbraco.Core if (_currentAssembliesHash != -1) return _currentAssembliesHash; - _currentAssembliesHash = GetAssembliesHash(new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Bin)).GetFiles("*.dll")); + _currentAssembliesHash = GetAssembliesHash( + new FileSystemInfo[] + { + //add the bin folder and everything in it + new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Bin)), + //add the app code folder and everything in it + new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Root + "/App_Code")), + //add the global.asax (the app domain also monitors this, if it changes will do a full restart) + new FileInfo(IOHelper.MapPath(SystemDirectories.Root + "/global.asax")) + } + ); return _currentAssembliesHash; } } @@ -178,17 +188,17 @@ namespace Umbraco.Core /// /// Returns a unique hash for the combination of FileInfo objects passed in /// - /// + /// /// - internal static long GetAssembliesHash(IEnumerable plugins) + internal static long GetAssembliesHash(IEnumerable filesAndFolders) { - using (DisposableTimer.TraceDuration("Determining hash of plugins on disk", "Hash determined")) + using (DisposableTimer.TraceDuration("Determining hash of code files on disk", "Hash determined")) { var hashCombiner = new HashCodeCombiner(); //add each unique folder to the hash - foreach (var i in plugins.Select(x => x.Directory).DistinctBy(x => x.FullName)) + foreach (var i in filesAndFolders.DistinctBy(x => x.FullName)) { - hashCombiner.AddFolder(i); + hashCombiner.AddFileSystemItem(i); } return ConvertPluginsHashFromHex(hashCombiner.GetCombinedHashCode()); }