From e3f4b86f1c28e0ec30a1ad2a079e308af4cbfbf7 Mon Sep 17 00:00:00 2001 From: Paul Johnson Date: Fri, 10 Jun 2022 09:03:59 +0100 Subject: [PATCH] Fix attempting to write lock files to LocalTempPath before it exists (#12563) --- .../Runtime/FileSystemMainDomLock.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Infrastructure/Runtime/FileSystemMainDomLock.cs b/src/Umbraco.Infrastructure/Runtime/FileSystemMainDomLock.cs index 37e962a222..a7b1610010 100644 --- a/src/Umbraco.Infrastructure/Runtime/FileSystemMainDomLock.cs +++ b/src/Umbraco.Infrastructure/Runtime/FileSystemMainDomLock.cs @@ -1,8 +1,4 @@ -using System; using System.Diagnostics; -using System.IO; -using System.Threading; -using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; @@ -14,6 +10,7 @@ namespace Umbraco.Cms.Infrastructure.Runtime internal class FileSystemMainDomLock : IMainDomLock { private readonly ILogger _logger; + private readonly IHostingEnvironment _hostingEnvironment; private readonly IOptionsMonitor _globalSettings; private readonly CancellationTokenSource _cancellationTokenSource = new(); private readonly string _lockFilePath; @@ -29,6 +26,7 @@ namespace Umbraco.Cms.Infrastructure.Runtime IOptionsMonitor globalSettings) { _logger = logger; + _hostingEnvironment = hostingEnvironment; _globalSettings = globalSettings; var lockFileName = $"MainDom_{mainDomKeyGenerator.GenerateKey()}.lock"; @@ -45,6 +43,7 @@ namespace Umbraco.Cms.Infrastructure.Runtime { try { + Directory.CreateDirectory(_hostingEnvironment.LocalTempPath); _logger.LogDebug("Attempting to obtain MainDom lock file handle {lockFilePath}", _lockFilePath); _lockFileStream = File.Open(_lockFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); DeleteLockReleaseSignalFile();