Skip to content

Commit 77d8962

Browse files
Forgindgithub-actions
authored andcommitted
Attempt to resolve workload gc bug
1 parent 5ff7dda commit 77d8962

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.Deployment.DotNet.Releases;
5+
6+
namespace Microsoft.DotNet.Workloads.Workload
7+
{
8+
internal class WorkloadUtilities
9+
{
10+
internal static int VersionCompare(string first, string second)
11+
{
12+
if (first.Equals(second))
13+
{
14+
return 0;
15+
}
16+
17+
var firstDash = first.IndexOf('-');
18+
var secondDash = second.IndexOf('-');
19+
firstDash = firstDash < 0 ? first.Length : firstDash;
20+
secondDash = secondDash < 0 ? second.Length : secondDash;
21+
22+
var firstVersion = new Version(first.Substring(0, firstDash));
23+
var secondVersion = new Version(second.Substring(0, secondDash));
24+
25+
var comparison = firstVersion.CompareTo(secondVersion);
26+
if (comparison != 0)
27+
{
28+
return comparison;
29+
}
30+
31+
var modifiedFirst = "1.1.1" + (firstDash == first.Length ? string.Empty : first.Substring(firstDash));
32+
var modifiedSecond = "1.1.1" + (secondDash == second.Length ? string.Empty : second.Substring(secondDash));
33+
34+
return new ReleaseVersion(modifiedFirst).CompareTo(new ReleaseVersion(modifiedSecond));
35+
}
36+
}
37+
}

src/Cli/dotnet/commands/dotnet-workload/install/WorkloadGarbageCollector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void GarbageCollectWorkloadSets()
115115
// If there isn't a rollback state file, don't garbage collect the latest workload set installed for the feature band
116116
if (installedWorkloadSets.Any())
117117
{
118-
var latestWorkloadSetVersion = installedWorkloadSets.Keys.MaxBy(k => new ReleaseVersion(k));
118+
var latestWorkloadSetVersion = installedWorkloadSets.Keys.Aggregate((s1, s2) => WorkloadUtilities.VersionCompare(s1, s2) >= 0 ? s1 : s2);
119119
_workloadSets[latestWorkloadSetVersion] = GCAction.Keep;
120120
_verboseReporter.WriteLine($"GC: Keeping latest installed workload set version {latestWorkloadSetVersion}");
121121
}

0 commit comments

Comments
 (0)