From bf8d6b6e851e11bb0519debf135403db78f4eb18 Mon Sep 17 00:00:00 2001 From: Brennan Date: Tue, 19 Dec 2023 16:53:17 -0800 Subject: [PATCH 1/2] Fix shadow copy up to date check on startup (#52831) --- .../CommonLib/Environment.cpp | 2 +- .../IIS.ShadowCopy.Tests/ShadowCopyTests.cs | 35 +++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/Environment.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/Environment.cpp index 7096cf85b808..c49200ce8d2f 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/Environment.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/Environment.cpp @@ -231,7 +231,7 @@ bool Environment::CheckUpToDate(const std::wstring& source, const std::filesyste auto sourceInnerDirectory = std::filesystem::directory_entry(path); if (sourceInnerDirectory.path() != directoryToIgnore) { - CheckUpToDate(destination / path.path().filename(), path.path(), extension, directoryToIgnore); + CheckUpToDate(/* source */ path.path(), /* destination */ destination / path.path().filename(), extension, directoryToIgnore); } } } diff --git a/src/Servers/IIS/IIS/test/IIS.ShadowCopy.Tests/ShadowCopyTests.cs b/src/Servers/IIS/IIS/test/IIS.ShadowCopy.Tests/ShadowCopyTests.cs index f4b93e637b33..eb5288190037 100644 --- a/src/Servers/IIS/IIS/test/IIS.ShadowCopy.Tests/ShadowCopyTests.cs +++ b/src/Servers/IIS/IIS/test/IIS.ShadowCopy.Tests/ShadowCopyTests.cs @@ -1,9 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; -using System.IO; -using System.Threading.Tasks; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; using Microsoft.AspNetCore.Testing; using Xunit; @@ -142,6 +140,37 @@ public async Task ShadowCopySingleFileChangedWorks() Assert.True(response.IsSuccessStatusCode); } + [ConditionalFact] + public async Task ShadowCopyDeleteFolderDuringShutdownWorks() + { + using var directory = TempDirectory.Create(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); + deploymentParameters.HandlerSettings["enableShadowCopy"] = "true"; + deploymentParameters.HandlerSettings["shadowCopyDirectory"] = directory.DirectoryPath; + + var deploymentResult = await DeployAsync(deploymentParameters); + var deleteDirPath = Path.Combine(deploymentResult.ContentRoot, "wwwroot/deletethis"); + Directory.CreateDirectory(deleteDirPath); + File.WriteAllText(Path.Combine(deleteDirPath, "file.dll"), ""); + + var response = await deploymentResult.HttpClient.GetAsync("Wow!"); + Assert.True(response.IsSuccessStatusCode); + + AddAppOffline(deploymentResult.ContentRoot); + await AssertAppOffline(deploymentResult); + + // Delete folder + file after app is shut down + // Testing specific path on startup where we compare the app directory contents with the shadow copy directory + Directory.Delete(deleteDirPath, recursive: true); + + RemoveAppOffline(deploymentResult.ContentRoot); + + await deploymentResult.AssertRecycledAsync(); + + response = await deploymentResult.HttpClient.GetAsync("Wow!"); + Assert.True(response.IsSuccessStatusCode); + } + [ConditionalFact] public async Task ShadowCopyE2EWorksWithFolderPresent() { From 0ec9b9876c25bd761f9530cf9a382e84386b3a37 Mon Sep 17 00:00:00 2001 From: Brennan Date: Fri, 10 May 2024 10:50:08 -0700 Subject: [PATCH 2/2] using --- .../IIS/IIS/test/IIS.ShadowCopy.Tests/ShadowCopyTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Servers/IIS/IIS/test/IIS.ShadowCopy.Tests/ShadowCopyTests.cs b/src/Servers/IIS/IIS/test/IIS.ShadowCopy.Tests/ShadowCopyTests.cs index eb5288190037..68dc2e78215b 100644 --- a/src/Servers/IIS/IIS/test/IIS.ShadowCopy.Tests/ShadowCopyTests.cs +++ b/src/Servers/IIS/IIS/test/IIS.ShadowCopy.Tests/ShadowCopyTests.cs @@ -1,7 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.AspNetCore.InternalTesting; +using System; +using System.IO; +using System.Threading.Tasks; using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; using Microsoft.AspNetCore.Testing; using Xunit;