diff --git a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/FindArchiveDiffs.cs b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/FindArchiveDiffs.cs index 1d1c7108b..ac6a44462 100644 --- a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/FindArchiveDiffs.cs +++ b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/FindArchiveDiffs.cs @@ -43,13 +43,13 @@ public class FindArchiveDiffs : Microsoft.Build.Utilities.Task, ICancelableTask { var baselineTask = Archive.Create(BaselineArchive.ItemSpec); var testTask = Archive.Create(TestArchive.ItemSpec); - Task.WaitAll(baselineTask, testTask); + Task.WaitAll([baselineTask, testTask], cancellationToken); using var baseline = await baselineTask; using var test = await testTask; var baselineFiles = baseline.GetFileNames(); var testFiles = test.GetFileNames(); ContentDifferences = - GetDiffs(baselineFiles, testFiles, PathWithVersions.Equal, PathWithVersions.GetVersionlessPath) + GetDiffs(baselineFiles, testFiles, PathWithVersions.Equal, PathWithVersions.GetVersionlessPath, cancellationToken) .Select(FromDiff) .ToArray(); return true; @@ -73,8 +73,10 @@ public class FindArchiveDiffs : Microsoft.Build.Utilities.Task, ICancelableTask string[] originalPathsWithVersions, string[] modifiedPathsWithVersions, Func equalityComparer, - Func? formatter = null) + Func? formatter = null, + CancellationToken cancellationToken = default) { + cancellationToken.ThrowIfCancellationRequested(); formatter ??= static s => s; // Edit distance algorithm: https://en.wikipedia.org/wiki/Longest_common_subsequence @@ -93,6 +95,7 @@ public class FindArchiveDiffs : Microsoft.Build.Utilities.Task, ICancelableTask // Compute edit distance for (int i = 1; i <= originalPathsWithVersions.Length; i++) { + cancellationToken.ThrowIfCancellationRequested(); for (int j = 1; j <= modifiedPathsWithVersions.Length; j++) { if (equalityComparer(originalPathsWithVersions[i - 1], modifiedPathsWithVersions[j - 1])) @@ -113,6 +116,7 @@ public class FindArchiveDiffs : Microsoft.Build.Utilities.Task, ICancelableTask List<(string, DifferenceKind)> formattedDiff = []; while (row > 0 || col > 0) { + cancellationToken.ThrowIfCancellationRequested(); var baselineItem = originalPathsWithVersions[row - 1]; var testItem = modifiedPathsWithVersions[col - 1]; if (row > 0 && col > 0 && PathWithVersions.Equal(baselineItem, testItem)) diff --git a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/PathWithVersions.cs b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/PathWithVersions.cs index bc2af0c6b..28a1f854e 100644 --- a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/PathWithVersions.cs +++ b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/PathWithVersions.cs @@ -80,16 +80,16 @@ public static class PathWithVersions StringBuilder sb = new StringBuilder(); bool altered = false; ReadOnlySpan myPath = path; - while (TryGetPathLeaf(myPath, out var directory, out var directoryPart)) + while (TryGetPathLeaf(myPath, out var root, out var leaf)) { - sb = sb.Insert(0, Path.DirectorySeparatorChar); - var versionOrDirectory = ReplaceVersionString(directoryPart); + var versionOrDirectory = ReplaceVersionString(leaf); if (versionOrDirectory == VersionPlaceholder) { altered = true; } sb = sb.Insert(0, versionOrDirectory); - myPath = directory; + sb = sb.Insert(0, Path.DirectorySeparatorChar); + myPath = root; } if (!altered) return path;