From 3259a2c9f60911e59d2c037eadb8a8bf38e1c7b6 Mon Sep 17 00:00:00 2001 From: Brennan Date: Fri, 7 Jun 2019 15:32:08 -0700 Subject: [PATCH] Prefer File.Move for DataProtection key creation + Fallback (#10990) --- .../src/Repositories/FileSystemXmlRepository.cs | 13 +++++++++++-- .../Authentication/test/SecureDataFormatTests.cs | 3 +-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/DataProtection/DataProtection/src/Repositories/FileSystemXmlRepository.cs b/src/DataProtection/DataProtection/src/Repositories/FileSystemXmlRepository.cs index 9eef2e2f18..19e11b6ac9 100644 --- a/src/DataProtection/DataProtection/src/Repositories/FileSystemXmlRepository.cs +++ b/src/DataProtection/DataProtection/src/Repositories/FileSystemXmlRepository.cs @@ -143,8 +143,17 @@ namespace Microsoft.AspNetCore.DataProtection.Repositories // Renames are atomic operations on the file systems we support. _logger.WritingDataToFile(finalFilename); - // Use File.Copy because File.Move on NFS shares has issues in .NET Core 2.0 - File.Copy(tempFilename, finalFilename); + try + { + // Prefer the atomic move operation to avoid multi-process startup issues + File.Move(tempFilename, finalFilename); + } + catch (IOException) + { + // Use File.Copy because File.Move on NFS shares has issues in .NET Core 2.0 + // See https://github.com/aspnet/AspNetCore/issues/2941 for more context + File.Copy(tempFilename, finalFilename); + } } finally { diff --git a/src/Security/Authentication/test/SecureDataFormatTests.cs b/src/Security/Authentication/test/SecureDataFormatTests.cs index 9ff1c26728..a30da3b91b 100644 --- a/src/Security/Authentication/test/SecureDataFormatTests.cs +++ b/src/Security/Authentication/test/SecureDataFormatTests.cs @@ -48,8 +48,7 @@ namespace Microsoft.AspNetCore.Authentication.DataHandler Assert.Equal(input, result); } - [ConditionalFact] - [SkipOnHelix("https://github.com/aspnet/AspNetCore-Internal/issues/1974")] + [Fact] public void UnprotectWithDifferentPurposeFails() { var provider = ServiceProvider.GetRequiredService();