diff --git a/src/Umbraco.Core/Models/TemplateOnDisk.cs b/src/Umbraco.Core/Models/TemplateOnDisk.cs index 7f89b47e34..a8420adcb6 100644 --- a/src/Umbraco.Core/Models/TemplateOnDisk.cs +++ b/src/Umbraco.Core/Models/TemplateOnDisk.cs @@ -39,8 +39,7 @@ namespace Umbraco.Core.Models { get { - if (IsOnDisk) throw new InvalidOperationException("On-disk template do not have content until saved."); - return base.Content; + return IsOnDisk ? string.Empty : base.Content; } set { diff --git a/src/Umbraco.Core/Persistence/Repositories/FileRepository.cs b/src/Umbraco.Core/Persistence/Repositories/FileRepository.cs index e1e4c3105a..7ce0d71097 100644 --- a/src/Umbraco.Core/Persistence/Repositories/FileRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/FileRepository.cs @@ -217,10 +217,20 @@ namespace Umbraco.Core.Persistence.Repositories protected string GetFileContent(string filename) { - using (var stream = FileSystem.OpenFile(filename)) - using (var reader = new StreamReader(stream, Encoding.UTF8, true)) + if (FileSystem.FileExists(filename) == false) + return null; + + try { - return reader.ReadToEnd(); + using (var stream = FileSystem.OpenFile(filename)) + using (var reader = new StreamReader(stream, Encoding.UTF8, true)) + { + return reader.ReadToEnd(); + } + } + catch + { + return null; // deal with race conds } } diff --git a/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs b/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs index 34cbd30df7..5ee83a47a8 100644 --- a/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs @@ -418,6 +418,8 @@ namespace Umbraco.Core.Persistence.Repositories fsname = string.Concat(template.Alias, ".master"); if (_masterpagesFileSystem.FileExists(fsname)) return GetFileContent(template, _masterpagesFileSystem, fsname, init); + + template.VirtualPath = string.Empty; // file not found... return string.Empty; } @@ -454,7 +456,17 @@ namespace Umbraco.Core.Persistence.Repositories public Stream GetFileContent(string filepath) { - return GetFileSystem(filepath).OpenFile(filepath); + var fs = GetFileSystem(filepath); + if (fs.FileExists(filepath) == false) return null; + + try + { + return GetFileSystem(filepath).OpenFile(filepath); + } + catch + { + return null; // deal with race conds + } } public void SetFileContent(string filepath, Stream content) diff --git a/src/Umbraco.Core/Services/MediaService.cs b/src/Umbraco.Core/Services/MediaService.cs index 121b7f508e..7cd1c2ab00 100644 --- a/src/Umbraco.Core/Services/MediaService.cs +++ b/src/Umbraco.Core/Services/MediaService.cs @@ -1261,7 +1261,16 @@ namespace Umbraco.Core.Services public Stream GetMediaFileContent(string filepath) { - return MediaHelper.FileSystem.OpenFile(filepath); + if (MediaHelper.FileSystem.FileExists(filepath) == false) + return null; + try + { + return MediaHelper.FileSystem.OpenFile(filepath); + } + catch + { + return null; // deal with race conds + } } public void SetMediaFileContent(string filepath, Stream stream) diff --git a/src/Umbraco.Web.UI/config/ClientDependency.config b/src/Umbraco.Web.UI/config/ClientDependency.config index 80d8db2da3..fd5df58715 100644 --- a/src/Umbraco.Web.UI/config/ClientDependency.config +++ b/src/Umbraco.Web.UI/config/ClientDependency.config @@ -10,7 +10,7 @@ NOTES: * Compression/Combination/Minification is not enabled unless debug="false" is specified on the 'compiliation' element in the web.config * A new version will invalidate both client and server cache and create new persisted files --> - +