-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid workload gc failure due to 4-part version in ReleaseVersion use…
…d to find a max (#45263)
- Loading branch information
Showing
3 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/Cli/dotnet/commands/dotnet-workload/WorkloadUtilities.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.Deployment.DotNet.Releases; | ||
|
||
namespace Microsoft.DotNet.Workloads.Workload | ||
{ | ||
internal class WorkloadUtilities | ||
{ | ||
internal static int VersionCompare(string first, string second) | ||
{ | ||
if (first.Equals(second)) | ||
{ | ||
return 0; | ||
} | ||
|
||
var firstDash = first.IndexOf('-'); | ||
var secondDash = second.IndexOf('-'); | ||
firstDash = firstDash < 0 ? first.Length : firstDash; | ||
secondDash = secondDash < 0 ? second.Length : secondDash; | ||
|
||
var firstVersion = new Version(first.Substring(0, firstDash)); | ||
var secondVersion = new Version(second.Substring(0, secondDash)); | ||
|
||
var comparison = firstVersion.CompareTo(secondVersion); | ||
if (comparison != 0) | ||
{ | ||
return comparison; | ||
} | ||
|
||
var modifiedFirst = new ReleaseVersion(1, 1, 1, firstDash == first.Length ? null : first.Substring(firstDash)); | ||
var modifiedSecond = new ReleaseVersion(1, 1, 1, secondDash == second.Length ? null : second.Substring(secondDash)); | ||
|
||
return modifiedFirst.CompareTo(modifiedSecond); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters