Skip to content

Commit 0742587

Browse files
committed
Apply code review feedback
1 parent 49a9b98 commit 0742587

File tree

6 files changed

+20
-26
lines changed

6 files changed

+20
-26
lines changed

src/Cli/dotnet/commands/InstallingWorkloadCommand.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ internal abstract class InstallingWorkloadCommand : WorkloadCommandBase
4646
protected IWorkloadManifestUpdater _workloadManifestUpdater;
4747

4848
protected bool UseRollback => !string.IsNullOrWhiteSpace(_fromRollbackDefinition);
49-
protected bool SpecifiedWorkloadSetVersionOnCommandLine => !string.IsNullOrEmpty(_workloadSetVersionFromCommandLine);
49+
protected bool SpecifiedWorkloadSetVersionOnCommandLine => !string.IsNullOrWhiteSpace(_workloadSetVersionFromCommandLine);
5050
protected bool SpecifiedWorkloadSetVersionInGlobalJson => !string.IsNullOrWhiteSpace(_workloadSetVersionFromGlobalJson);
5151

5252
public InstallingWorkloadCommand(
@@ -115,7 +115,6 @@ public InstallingWorkloadCommand(
115115
}
116116

117117
// At this point, at most one of SpecifiedWorkloadSetVersionOnCommandLine, UseRollback, and SpecifiedWorkloadSetVersionInGlobalJson is true
118-
119118
}
120119

121120
protected static Dictionary<string, string> GetInstallStateContents(IEnumerable<ManifestVersionUpdate> manifestVersionUpdates) =>
@@ -131,8 +130,7 @@ InstallStateContents GetCurrentInstallState()
131130
static InstallStateContents GetCurrentInstallState(SdkFeatureBand sdkFeatureBand, string dotnetDir)
132131
{
133132
string path = Path.Combine(WorkloadInstallType.GetInstallStateFolder(sdkFeatureBand, dotnetDir), "default.json");
134-
var installStateContents = File.Exists(path) ? InstallStateContents.FromString(File.ReadAllText(path)) : new InstallStateContents();
135-
return installStateContents;
133+
return InstallStateContents.FromPath(path);
136134
}
137135

138136
public static bool ShouldUseWorkloadSetMode(SdkFeatureBand sdkFeatureBand, string dotnetDir)
@@ -142,18 +140,18 @@ public static bool ShouldUseWorkloadSetMode(SdkFeatureBand sdkFeatureBand, strin
142140

143141
protected void UpdateWorkloadManifests(ITransactionContext context, DirectoryPath? offlineCache)
144142
{
145-
var updateUsingWorkloadSets = ShouldUseWorkloadSetMode(_sdkFeatureBand, _dotnetPath);
146-
if (UseRollback && updateUsingWorkloadSets)
143+
var updateToLatestWorkloadSet = ShouldUseWorkloadSetMode(_sdkFeatureBand, _dotnetPath);
144+
if (UseRollback && updateToLatestWorkloadSet)
147145
{
148146
// Rollback files are only for loose manifests. Update the mode to be loose manifests.
149147
Reporter.WriteLine(Update.LocalizableStrings.UpdateFromRollbackSwitchesModeToLooseManifests);
150148
_workloadInstaller.UpdateInstallMode(_sdkFeatureBand, false);
151-
updateUsingWorkloadSets = false;
149+
updateToLatestWorkloadSet = false;
152150
}
153151

154152
if (SpecifiedWorkloadSetVersionOnCommandLine)
155153
{
156-
updateUsingWorkloadSets = false;
154+
updateToLatestWorkloadSet = false;
157155

158156
// If a workload set version is specified, then switch to workload set update mode
159157
// Check to make sure the value needs to be changed, as updating triggers a UAC prompt
@@ -167,14 +165,14 @@ protected void UpdateWorkloadManifests(ITransactionContext context, DirectoryPat
167165
string resolvedWorkloadSetVersion = _workloadSetVersionFromGlobalJson ??_workloadSetVersionFromCommandLine;
168166
if (string.IsNullOrWhiteSpace(resolvedWorkloadSetVersion) && !UseRollback)
169167
{
170-
_workloadManifestUpdater.UpdateAdvertisingManifestsAsync(_includePreviews, updateUsingWorkloadSets, offlineCache).Wait();
171-
if (updateUsingWorkloadSets)
168+
_workloadManifestUpdater.UpdateAdvertisingManifestsAsync(_includePreviews, updateToLatestWorkloadSet, offlineCache).Wait();
169+
if (updateToLatestWorkloadSet)
172170
{
173171
resolvedWorkloadSetVersion = _workloadManifestUpdater.GetAdvertisedWorkloadSetVersion();
174172
}
175173
}
176174

177-
if (updateUsingWorkloadSets && resolvedWorkloadSetVersion == null)
175+
if (updateToLatestWorkloadSet && resolvedWorkloadSetVersion == null)
178176
{
179177
Reporter.WriteLine(Update.LocalizableStrings.NoWorkloadUpdateFound);
180178
return;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,13 @@ public WorkloadSet InstallWorkloadSet(ITransactionContext context, string worklo
267267
context.Run(
268268
action: () =>
269269
{
270-
Elevate();
271-
272270
DetectState state = DetectPackage(msi.ProductCode, out Version installedVersion);
273271
InstallAction plannedAction = PlanPackage(msi, state, InstallAction.Install, installedVersion);
274272

275273
if (plannedAction == InstallAction.Install)
276274
{
275+
Elevate();
276+
277277
ExecutePackage(msi, plannedAction, msiPackageId);
278278

279279
// Update the reference count against the MSI.
@@ -316,7 +316,7 @@ public WorkloadSet InstallWorkloadSet(ITransactionContext context, string worklo
316316
// Unwrap AggregateException caused by switch from async to sync
317317
catch (Exception ex) when (ex is NuGetPackageNotFoundException || ex.InnerException is NuGetPackageNotFoundException)
318318
{
319-
throw new GracefulException(string.Format(Update.LocalizableStrings.WorkloadVersionRequestedNotFound, workloadSetVersion), ex);
319+
throw new GracefulException(string.Format(Update.LocalizableStrings.WorkloadVersionRequestedNotFound, workloadSetVersion), ex is NuGetPackageNotFoundException ? ex : ex.InnerException);
320320
}
321321
VerifyPackage(msi);
322322

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,12 @@ public override int Execute()
125125
if (string.IsNullOrWhiteSpace(_workloadSetVersionFromCommandLine) && string.IsNullOrWhiteSpace(_workloadSetVersionFromGlobalJson))
126126
{
127127
var installStateFilePath = Path.Combine(WorkloadInstallType.GetInstallStateFolder(_sdkFeatureBand, _dotnetPath), "default.json");
128-
if (File.Exists(installStateFilePath))
128+
var installStateContents = InstallStateContents.FromPath(installStateFilePath);
129+
// If install state has pinned workload set or manifest versions, then don't update workloads
130+
if (!string.IsNullOrEmpty(installStateContents.WorkloadVersion) || installStateContents.Manifests != null)
129131
{
130-
var installStateContents = InstallStateContents.FromPath(installStateFilePath);
131-
// If install state has pinned workload set or manifest versions, then don't update workloads
132-
if (!string.IsNullOrEmpty(installStateContents.WorkloadVersion) || installStateContents.Manifests != null)
133-
{
134-
// TODO: respect shouldUpdateWorkloads, or figure out update / install manifest difference in InstallingWorkloadCommand
135-
shouldUpdateWorkloads = false;
136-
}
132+
// TODO: respect shouldUpdateWorkloads, or figure out update / install manifest difference in InstallingWorkloadCommand
133+
shouldUpdateWorkloads = false;
137134
}
138135
}
139136

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,6 @@ private async Task<bool> NewerManifestPackageExists(ManifestId manifest)
485485

486486
public IEnumerable<ManifestVersionUpdate> CalculateManifestUpdatesForWorkloadSet(WorkloadSet workloadSet)
487487
{
488-
// TODO: Don't look up previous manifest versions (since we may be in the mode where there's a global.json with a workload set
489-
// that's not installed, and trying to get the current manifests will throw an exception)
490488
return CalculateManifestRollbacks(workloadSet.ManifestVersions.Select(kvp => (kvp.Key, new ManifestVersionWithBand(kvp.Value.Version, kvp.Value.FeatureBand))));
491489
}
492490

src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ public Dictionary<string, WorkloadSet> GetAvailableWorkloadSets(SdkFeatureBand w
501501

502502
foreach (var manifestRoot in _manifestRoots.Reverse())
503503
{
504-
// We don't automatically fall back to a previous band
505504
var workloadSetsRoot = Path.Combine(manifestRoot, workloadSetFeatureBand.ToString(), WorkloadSetsFolderName);
506505
if (Directory.Exists(workloadSetsRoot))
507506
{

src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/WorkloadSet.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ public static string WorkloadSetVersionToWorkloadSetPackageVersion(string setVer
169169

170170
if (preReleaseOrBuild != null)
171171
{
172-
packageVersion += '-' + preReleaseOrBuild;
172+
// Figure out if we split on a '-' or '+'
173+
char separator = setVersion[sections[0].Length];
174+
packageVersion += separator + preReleaseOrBuild;
173175
}
174176

175177
return packageVersion;

0 commit comments

Comments
 (0)