Skip to content

Commit 8634876

Browse files
committed
Fix handling installer shutdown in workload restore command
1 parent 11239cf commit 8634876

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ internal class WorkloadInstallCommand : InstallingWorkloadCommand
2020
{
2121
private bool _skipManifestUpdate;
2222
private readonly IReadOnlyCollection<string> _workloadIds;
23+
private readonly bool _shouldShutdownInstaller;
2324

2425
public bool IsRunningRestore { get; set; }
2526

@@ -45,6 +46,7 @@ public WorkloadInstallCommand(
4546
WorkloadInstallerFactory.GetWorkloadInstaller(resolvedReporter, _sdkFeatureBand,
4647
_workloadResolver, Verbosity, _userProfileDir, VerifySignatures, PackageDownloader, _dotnetPath, TempDirectoryPath,
4748
_packageSourceLocation, RestoreActionConfiguration, elevationRequired: !_printDownloadLinkOnly && string.IsNullOrWhiteSpace(_downloadToCacheOption));
49+
_shouldShutdownInstaller = _workloadInstallerFromConstructor != null;
4850

4951
_workloadManifestUpdater = _workloadManifestUpdaterFromConstructor ?? new WorkloadManifestUpdater(resolvedReporter, _workloadResolver, PackageDownloader, _userProfileDir,
5052
_workloadInstaller.GetWorkloadInstallationRecordRepository(), _workloadInstaller, _packageSourceLocation, displayManifestUpdates: Verbosity.IsDetailedOrDiagnostic());
@@ -146,14 +148,21 @@ public override int Execute()
146148
}
147149
catch (Exception e)
148150
{
149-
_workloadInstaller.Shutdown();
151+
if (_shouldShutdownInstaller)
152+
{
153+
_workloadInstaller.Shutdown();
154+
}
150155

151156
// Don't show entire stack trace
152157
throw new GracefulException(string.Format(LocalizableStrings.WorkloadInstallationFailed, e.Message), e, isUserError: false);
153158
}
154159
}
155160

156-
_workloadInstaller.Shutdown();
161+
if (_shouldShutdownInstaller)
162+
{
163+
_workloadInstaller.Shutdown();
164+
}
165+
157166
return _workloadInstaller.ExitCode;
158167
}
159168

src/Cli/dotnet/commands/dotnet-workload/restore/WorkloadRestoreCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override int Execute()
5151
recorder.Run(() =>
5252
{
5353
// First update manifests and install a workload set as necessary
54-
new WorkloadUpdateCommand(_result, recorder: recorder).Execute();
54+
new WorkloadUpdateCommand(_result, recorder: recorder, isRestoring: true).Execute();
5555

5656
var allProjects = DiscoverAllProjects(Directory.GetCurrentDirectory(), _slnOrProjectArgument).Distinct();
5757
List<WorkloadId> allWorkloadId = RunTargetToGetWorkloadIds(allProjects);
@@ -64,6 +64,8 @@ public override int Execute()
6464
IsRunningRestore = true
6565
}.Execute();
6666
});
67+
68+
workloadInstaller.Shutdown();
6769

6870
return 0;
6971
}

src/Cli/dotnet/commands/dotnet-workload/update/WorkloadUpdateCommand.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal class WorkloadUpdateCommand : InstallingWorkloadCommand
2323
private readonly bool _fromPreviousSdk;
2424
private WorkloadHistoryRecorder _recorder;
2525
private readonly bool _isRestoring;
26+
private readonly bool _shouldShutdownInstaller;
2627
public WorkloadUpdateCommand(
2728
ParseResult parseResult,
2829
IReporter reporter = null,
@@ -49,6 +50,9 @@ public WorkloadUpdateCommand(
4950
_dotnetPath, TempDirectoryPath, packageSourceLocation: _packageSourceLocation, RestoreActionConfiguration,
5051
elevationRequired: !_printDownloadLinkOnly && !_printRollbackDefinitionOnly && string.IsNullOrWhiteSpace(_downloadToCacheOption));
5152

53+
_shouldShutdownInstaller = _workloadInstallerFromConstructor != null;
54+
55+
5256
_workloadManifestUpdater = _workloadManifestUpdaterFromConstructor ?? new WorkloadManifestUpdater(resolvedReporter, _workloadResolver, PackageDownloader, _userProfileDir,
5357
_workloadInstaller.GetWorkloadInstallationRecordRepository(), _workloadInstaller, _packageSourceLocation, sdkFeatureBand: _sdkFeatureBand);
5458
_recorder = recorder;
@@ -132,7 +136,10 @@ public override int Execute()
132136
}
133137
}
134138

135-
_workloadInstaller.Shutdown();
139+
if (_shouldShutdownInstaller)
140+
{
141+
_workloadInstaller.Shutdown();
142+
}
136143
return _workloadInstaller.ExitCode;
137144
}
138145

0 commit comments

Comments
 (0)