Skip to content

Commit

Permalink
Clone the delete-before-copy escape hatch from MSBuild Copy.cs to all…
Browse files Browse the repository at this point in the history
…ow turning it off in some repos
  • Loading branch information
erikmav committed Dec 7, 2023
1 parent 3c00cb0 commit e2d22b7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/CopyOnWrite/Copy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class Copy : Task, ICancelableTask
internal const string AlwaysOverwriteReadOnlyFilesEnvVar = "MSBUILDALWAYSOVERWRITEREADONLYFILES";
private static readonly bool IsWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;

// Escape hatch taken from MSBuild Traits.cs that allow turning off delete-before-copy logic.
private static readonly bool CopyWithoutDeleteEscapeHatch = Environment.GetEnvironmentVariable("MSBUILDCOPYWITHOUTDELETE") == "1";

// Default parallelism determined empirically - times below are in seconds spent in the Copy task building this repo
// with "build -skiptests -rebuild -configuration Release /ds" (with hack to build.ps1 to disable creating selfhost
// build for non-selfhost first build; implies first running build in repo to pull packages and create selfhost)
Expand Down Expand Up @@ -265,7 +268,8 @@ private void LogDiagnostic(string message, params object[] messageArgs)
MakeFileWriteable(destinationFileState, true);
}

if (destinationFileState.FileExists &&
if (!CopyWithoutDeleteEscapeHatch &&
destinationFileState.FileExists &&
!destinationFileState.IsReadOnly)
{
FileUtilities.DeleteNoThrow(destinationFileState.Name);
Expand Down

0 comments on commit e2d22b7

Please sign in to comment.