Skip to content

Commit c0e2067

Browse files
nagilsondsplaisted
authored andcommitted
Use the same release index so we don't download it twice
1 parent 0451e81 commit c0e2067

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

src/Installer/Microsoft.Dotnet.Installation/Internal/ArchiveDotnetExtractor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,24 @@ internal class ArchiveDotnetExtractor : IDisposable
1919
private readonly DotnetInstallRequest _request;
2020
private readonly ReleaseVersion _resolvedVersion;
2121
private readonly IProgressTarget _progressTarget;
22+
private readonly ReleaseManifest _releaseManifest;
2223
private string scratchDownloadDirectory;
2324
private string? _archivePath;
2425

25-
public ArchiveDotnetExtractor(DotnetInstallRequest request, ReleaseVersion resolvedVersion, IProgressTarget progressTarget)
26+
public ArchiveDotnetExtractor(DotnetInstallRequest request, ReleaseVersion resolvedVersion, ReleaseManifest releaseManifest, IProgressTarget progressTarget)
2627
{
2728
_request = request;
2829
_resolvedVersion = resolvedVersion;
2930
_progressTarget = progressTarget;
31+
_releaseManifest = new();
3032
scratchDownloadDirectory = Directory.CreateTempSubdirectory().FullName;
3133
}
3234

3335
public void Prepare()
3436
{
3537
using var activity = InstallationActivitySource.ActivitySource.StartActivity("DotnetInstaller.Prepare");
3638

37-
using var archiveDownloader = new DotnetArchiveDownloader();
39+
using var archiveDownloader = new DotnetArchiveDownloader(_releaseManifest);
3840
var archiveName = $"dotnet-{Guid.NewGuid()}";
3941
_archivePath = Path.Combine(scratchDownloadDirectory, archiveName + DnupUtilities.GetArchiveFileExtensionForPlatform());
4042

src/Installer/Microsoft.Dotnet.Installation/Internal/ChannelVersionResolver.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ namespace Microsoft.Dotnet.Installation.Internal;
1010

1111
internal class ChannelVersionResolver
1212
{
13-
public IEnumerable<string> GetSupportedChannels()
13+
private ReleaseManifest _releaseManifest = new();
14+
15+
public ChannelVersionResolver()
1416
{
15-
// TODO: Share this with other methods from this class
16-
var productIndex = ProductCollection.GetAsync().GetAwaiter().GetResult();
1717

18+
}
19+
20+
public ChannelVersionResolver(ReleaseManifest releaseManifest)
21+
{
22+
_releaseManifest = releaseManifest;
23+
}
24+
25+
public IEnumerable<string> GetSupportedChannels()
26+
{
27+
var productIndex = _releaseManifest.GetReleasesIndex();
1828
return ["latest", "preview", "lts", "sts",
1929
..productIndex
2030
.Where(p => p.IsSupported)
@@ -85,17 +95,17 @@ static IEnumerable<string> GetChannelsForProduct(Product product)
8595
if (string.Equals(channel.Name, "lts", StringComparison.OrdinalIgnoreCase) || string.Equals(channel.Name, "sts", StringComparison.OrdinalIgnoreCase))
8696
{
8797
var releaseType = string.Equals(channel.Name, "lts", StringComparison.OrdinalIgnoreCase) ? ReleaseType.LTS : ReleaseType.STS;
88-
var productIndex = ProductCollection.GetAsync().GetAwaiter().GetResult();
98+
var productIndex = _releaseManifest.GetReleasesIndex();
8999
return GetLatestVersionByReleaseType(productIndex, releaseType, component);
90100
}
91101
else if (string.Equals(channel.Name, "preview", StringComparison.OrdinalIgnoreCase))
92102
{
93-
var productIndex = ProductCollection.GetAsync().GetAwaiter().GetResult();
103+
var productIndex = _releaseManifest.GetReleasesIndex();
94104
return GetLatestPreviewVersion(productIndex, component);
95105
}
96106
else if (string.Equals(channel.Name, "latest", StringComparison.OrdinalIgnoreCase))
97107
{
98-
var productIndex = ProductCollection.GetAsync().GetAwaiter().GetResult();
108+
var productIndex = _releaseManifest.GetReleasesIndex();
99109
return GetLatestActiveVersion(productIndex, component);
100110
}
101111

@@ -114,7 +124,7 @@ static IEnumerable<string> GetChannelsForProduct(Product product)
114124
}
115125

116126
// Load the index manifest
117-
var index = ProductCollection.GetAsync().GetAwaiter().GetResult();
127+
var index = _releaseManifest.GetReleasesIndex();
118128
if (minor < 0)
119129
{
120130
return GetLatestVersionForMajorOrMajorMinor(index, major, component); // Major Only (e.g., "9")
@@ -241,7 +251,7 @@ private static int NormalizeFeatureBandInput(string band)
241251

242252
var validProducts = GetProductsInMajorOrMajorMinor(index, major, minor);
243253
var latestProduct = validProducts.FirstOrDefault();
244-
var releases = latestProduct?.GetReleasesAsync().GetAwaiter().GetResult().ToList() ?? new List<ProductRelease>();
254+
var releases = latestProduct?.GetReleasesAsync().GetAwaiter().GetResult().ToList() ?? [];
245255
var normalizedFeatureBand = NormalizeFeatureBandInput(featureBand);
246256

247257
foreach (var release in releases)

src/Installer/Microsoft.Dotnet.Installation/Internal/DotnetArchiveDownloader.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public DotnetArchiveDownloader()
3232
{
3333
}
3434

35+
public DotnetArchiveDownloader(ReleaseManifest releaseManifest)
36+
: this(CreateDefaultHttpClient())
37+
{
38+
_releaseManifest = releaseManifest ?? throw new ArgumentNullException(nameof(releaseManifest));
39+
}
40+
3541
/// <summary>
3642
/// Creates an HttpClient with enhanced proxy support for enterprise environments.
3743
/// </summary>

src/Installer/Microsoft.Dotnet.Installation/Internal/DotnetInstaller.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ public void Install(DotnetInstallRoot dotnetRoot, InstallComponent component, Re
2626
activity?.SetTag("install.component", component.ToString());
2727
activity?.SetTag("install.version", version.ToString());
2828

29+
ReleaseManifest releaseManifest = new();
30+
2931
var installRequest = new DotnetInstallRequest(dotnetRoot, new UpdateChannel(version.ToString()), component, new InstallRequestOptions());
3032

31-
using ArchiveDotnetExtractor installer = new(installRequest, version, _progressTarget);
33+
using ArchiveDotnetExtractor installer = new(installRequest, version, releaseManifest, _progressTarget);
3234
installer.Prepare();
3335
installer.Commit();
3436
}

src/Installer/dnup/InstallerOrchestratorSingleton.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ private InstallerOrchestratorSingleton()
2525
public DotnetInstall? Install(DotnetInstallRequest installRequest, bool noProgress = false)
2626
{
2727
// Map InstallRequest to DotnetInstallObject by converting channel to fully specified version
28-
ReleaseVersion? versionToInstall = new ChannelVersionResolver().Resolve(installRequest);
28+
ReleaseManifest releaseManifest = new();
29+
ReleaseVersion? versionToInstall = new ChannelVersionResolver(releaseManifest).Resolve(installRequest);
2930

3031
if (versionToInstall == null)
3132
{
@@ -53,7 +54,7 @@ private InstallerOrchestratorSingleton()
5354

5455
IProgressTarget progressTarget = noProgress ? new NonUpdatingProgressTarget() : new SpectreProgressTarget();
5556

56-
using ArchiveDotnetExtractor installer = new(installRequest, versionToInstall, progressTarget);
57+
using ArchiveDotnetExtractor installer = new(installRequest, versionToInstall, releaseManifest, progressTarget);
5758
installer.Prepare();
5859

5960
// Extract and commit the install to the directory

0 commit comments

Comments
 (0)