Skip to content

Commit 0ce832b

Browse files
rootroot
authored andcommitted
Break up the install verification into smaller functions. Next, check the sudo fuctionality
1 parent e70ddc4 commit 0ce832b

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

vscode-dotnet-runtime-library/src/Acquisition/DotnetGlobalSDKLinuxInstallerResolver.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,8 @@ export class DotnetGlobalSDKLinuxInstallerResolver
100100
}
101101
}
102102

103-
private async ValidateVersionFeatureBand(version : string, existingGlobalDotnetVersion : string)
103+
private async VerifyNoConflictInstallTypeExists(supportStatus : DotnetDistroSupportStatus, fullySpecifiedDotnetVersion : string) : void
104104
{
105-
106-
107-
}
108-
109-
public async ValidateAndInstallSDK(fullySpecifiedDotnetVersion : string) : Promise<string>
110-
{
111-
// Verify the version of dotnet is supported
112-
if (!( await this.distroSDKProvider.isDotnetVersionSupported(fullySpecifiedDotnetVersion) ))
113-
{
114-
throw new Error(`The distro ${this.distro} does not officially support dotnet version ${fullySpecifiedDotnetVersion}.`);
115-
}
116-
117-
// Verify there are no conflicting installs
118-
// Check existing installs ...
119-
const supportStatus = await this.distroSDKProvider.getDotnetVersionSupportStatus(fullySpecifiedDotnetVersion);
120105
if(supportStatus === DotnetDistroSupportStatus.Distro)
121106
{
122107
const microsoftFeedDir = await this.distroSDKProvider.getExpectedDotnetMicrosoftFeedInstallationDirectory();
@@ -141,9 +126,10 @@ export class DotnetGlobalSDKLinuxInstallerResolver
141126
throw err;
142127
}
143128
}
129+
}
144130

145-
const existingInstall = await this.distroSDKProvider.getInstalledGlobalDotnetPathIfExists();
146-
// Check for a custom install
131+
private async VerifyNoCustomInstallExists(supportStatus : DotnetDistroSupportStatus, fullySpecifiedDotnetVersion : string, existingInstall : string | null) : void
132+
{
147133
if(existingInstall && path.resolve(existingInstall) !== path.resolve(supportStatus === DotnetDistroSupportStatus.Distro ? await this.distroSDKProvider.getExpectedDotnetDistroFeedInstallationDirectory() : await this.distroSDKProvider.getExpectedDotnetMicrosoftFeedInstallationDirectory() ))
148134
{
149135
const err = new DotnetCustomLinuxInstallExistsError(new Error(`A custom dotnet installation exists at ${existingInstall}.
@@ -153,8 +139,11 @@ export class DotnetGlobalSDKLinuxInstallerResolver
153139
this.acquisitionContext.eventStream.post(err);
154140
throw err;
155141
}
156-
// Check if we need to install or not, if we can install (if the version conflicts with an existing one), or if we can just update the existing install.
157-
else if(existingInstall)
142+
}
143+
144+
private async UpdateOrRejectIfVersionRequestDoesNotRequireInstall(fullySpecifiedDotnetVersion : string, existingInstall : string | null)
145+
{
146+
if(existingInstall)
158147
{
159148
const existingGlobalInstallSDKVersion = await this.distroSDKProvider.getInstalledGlobalDotnetVersionIfExists();
160149
if(existingGlobalInstallSDKVersion && Number(VersionResolver.getMajorMinor(existingGlobalInstallSDKVersion)) === Number(VersionResolver.getMajorMinor(fullySpecifiedDotnetVersion)))
@@ -181,6 +170,27 @@ export class DotnetGlobalSDKLinuxInstallerResolver
181170
}
182171
// Additional logic to check the major.minor could be added here if we wanted to prevent installing lower major.minors if an existing install existed.
183172
}
173+
}
174+
175+
public async ValidateAndInstallSDK(fullySpecifiedDotnetVersion : string) : Promise<string>
176+
{
177+
// Verify the version of dotnet is supported
178+
if (!( await this.distroSDKProvider.isDotnetVersionSupported(fullySpecifiedDotnetVersion) ))
179+
{
180+
throw new Error(`The distro ${this.distro} does not officially support dotnet version ${fullySpecifiedDotnetVersion}.`);
181+
}
182+
183+
// Verify there are no conflicting installs
184+
// Check existing installs ...
185+
const supportStatus = await this.distroSDKProvider.getDotnetVersionSupportStatus(fullySpecifiedDotnetVersion);
186+
await this.VerifyNoConflictInstallTypeExists(supportStatus, fullySpecifiedDotnetVersion);
187+
188+
const existingInstall = await this.distroSDKProvider.getInstalledGlobalDotnetPathIfExists();
189+
// Check for a custom install
190+
await this.VerifyNoCustomInstallExists(supportStatus, fullySpecifiedDotnetVersion, existingInstall);
191+
192+
// Check if we need to install or not, if we can install (if the version conflicts with an existing one), or if we can just update the existing install.
193+
await this.UpdateOrRejectIfVersionRequestDoesNotRequireInstall(fullySpecifiedDotnetVersion, existingInstall);
184194

185195
return await this.distroSDKProvider.installDotnet() ? '0' : '1';
186196
}

vscode-dotnet-runtime-library/src/Acquisition/IDistroDotnetSDKProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as fs from 'fs';
77
import { DistroVersionPair, DotnetDistroSupportStatus } from './DotnetGlobalSDKLinuxInstallerResolver';
88
import path = require('path');
99
import { DotnetAcquisitionDistroUnknownError } from '../EventStream/EventStreamEvents';
10+
import { VersionResolver } from './VersionResolver';
1011

1112
/**
1213
* This interface describes the functionality needed to manage the .NET SDK on a specific distro and version of Linux.
@@ -85,7 +86,8 @@ export abstract class IDistroDotnetSDKProvider {
8586
public async isDotnetVersionSupported(fullySpecifiedVersion : string)
8687
{
8788
const supportStatus = await this.getDotnetVersionSupportStatus(fullySpecifiedVersion);
88-
return supportStatus === DotnetDistroSupportStatus.Distro;
89+
const supportedType : boolean = supportStatus === DotnetDistroSupportStatus.Distro || supportStatus === DotnetDistroSupportStatus.Microsoft;
90+
return supportedType && VersionResolver.getFeatureBandFromVersion(fullySpecifiedVersion) === '1';
8991
}
9092

9193
/**

0 commit comments

Comments
 (0)