Skip to content

Commit 437acbe

Browse files
authored
Merge pull request #2497 from nagilson/nagilson-fix-offline-global-sdk-v
Only Check for Existing Installs if Offline on SDK Admin Installs
2 parents 42f70cf + 7e9b07a commit 437acbe

File tree

12 files changed

+326
-111
lines changed

12 files changed

+326
-111
lines changed

THIRD-PARTY-NOTICES.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
235235
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
236236
SOFTWARE.
237237

238+
-------------------------------
239+
240+
License notice for shelljs, minimatch, js-yaml
241+
https://github.com/jslicense/BlueOak-1.0.0/blob/main/BlueOak-1.0.0.md
242+
243+
-------------------------------
244+
245+
https://blueoakcouncil.org/license/1.0.0
238246

239247
-------------------------------
240248

package-lock.json

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vscode-dotnet-runtime-extension/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vscode-dotnet-runtime-extension/src/extension.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export function activate(vsCodeContext: vscode.ExtensionContext, extensionContex
325325

326326
globalEventStream.post(new DotnetAcquisitionRequested(commandContext.version, commandContext.requestingExtensionId ?? 'notProvided', commandContext.mode!, commandContext.installType ?? 'global'));
327327

328-
const existingOfflinePath = await getExistingInstallOffline(worker, workerContext);
328+
const existingOfflinePath = await getExistingInstallIfOffline(worker, workerContext);
329329
if (existingOfflinePath)
330330
{
331331
return Promise.resolve(existingOfflinePath);
@@ -449,6 +449,8 @@ export function activate(vsCodeContext: vscode.ExtensionContext, extensionContex
449449

450450
globalEventStream.post(new DotnetAcquisitionStatusRequested(commandContext.version, commandContext.requestingExtensionId));
451451

452+
// Caveat : acquireStatus expects only a major.minor, so fully specified versions won't be checked here
453+
452454
const existingOfflinePath = await getExistingInstallOffline(worker, workerContext);
453455
if (existingOfflinePath)
454456
{
@@ -962,6 +964,16 @@ ${JSON.stringify(commandContext)}`));
962964
};
963965
}
964966

967+
async function getExistingInstallIfOffline(worker: DotnetCoreAcquisitionWorker, workerContext: IAcquisitionWorkerContext): Promise<IDotnetAcquireResult | null>
968+
{
969+
const isOffline = !(await WebRequestWorkerSingleton.getInstance().isOnline(timeoutValue ?? defaultTimeoutValue, globalEventStream));
970+
if (isOffline)
971+
{
972+
return getExistingInstallOffline(worker, workerContext);
973+
}
974+
return null;
975+
}
976+
965977
async function getExistingInstallOffline(worker: DotnetCoreAcquisitionWorker, workerContext: IAcquisitionWorkerContext): Promise<IDotnetAcquireResult | null>
966978
{
967979
workerContext.acquisitionContext.architecture ??= DotnetCoreAcquisitionWorker.defaultArchitecture();

vscode-dotnet-runtime-extension/src/test/functional/DotnetCoreAcquisitionExtension.test.ts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -490,23 +490,16 @@ suite('DotnetCoreAcquisitionExtension End to End', function ()
490490
}
491491
}).timeout(standardTimeoutTime);
492492

493-
test('Install SDK Globally E2E (Requires Admin)', async () =>
493+
async function runGlobalSdkInstallTest(version: string)
494494
{
495-
// We only test if the process is running under ADMIN because non-admin requires user-intervention.
496-
const sdkVersion = '7.0.103';
497-
const context: IDotnetAcquireContext = { version: sdkVersion, requestingExtensionId: 'sample-extension', installType: 'global' };
495+
const context: IDotnetAcquireContext = { version, requestingExtensionId: 'sample-extension', installType: 'global' };
498496
if (await new FileUtilities().isElevated(getMockAcquisitionWorkerContext(context), getMockUtilityContext()))
499497
{
500498
const originalPath = process.env.PATH;
501-
502-
// We cannot use the describe pattern to restore the environment variables using vscode's extension testing infrastructure.
503-
// So we must set and unset it ourselves, which isn't ideal as this variable could remain.
504-
let result: IDotnetAcquireResult;
499+
let result: IDotnetAcquireResult | undefined;
505500
let error: any;
506-
let pathAfterInstall;
501+
let pathAfterInstall: string | undefined;
507502

508-
// We cannot test much as we don't want to leave global installs on dev boxes. But we do want to make sure the e-2-e goes through the right path. Vendors can test the rest.
509-
// So we have this environment variable that tells us to stop before running any real install.
510503
process.env.VSCODE_DOTNET_GLOBAL_INSTALL_FAKE_PATH = 'true';
511504
try
512505
{
@@ -521,25 +514,43 @@ suite('DotnetCoreAcquisitionExtension End to End', function ()
521514
pathAfterInstall = process.env.PATH;
522515
process.env.VSCODE_DOTNET_GLOBAL_INSTALL_FAKE_PATH = undefined;
523516
process.env.PATH = originalPath;
517+
}
524518

525-
if (error)
526-
{
527-
throw (new Error(`The test failed to run the acquire command successfully. Error: ${error}`));
528-
}
519+
if (error)
520+
{
521+
throw new Error(`The test failed to run the acquire command successfully for version ${version}. Error: ${error}`);
529522
}
530523

531-
assert.exists(result!, 'The global acquisition command did not provide a result?');
524+
assert.exists(result, `The global acquisition command did not provide a result for version ${version}`);
532525
assert.exists(result!.dotnetPath);
533526
assert.equal(result!.dotnetPath, 'fake-sdk');
534527
assert.exists(pathAfterInstall, 'The environment variable PATH for DOTNET was not found?');
535-
assert.include(pathAfterInstall, result!.dotnetPath, 'Is the PATH correctly set by the global installer?');
528+
assert.include(pathAfterInstall!, result!.dotnetPath, 'Is the PATH correctly set by the global installer?');
536529
}
537530
else
538531
{
539-
// We could run the installer without privilege but it would require human interaction to use the UAC
540-
// And we wouldn't be able to kill the process so the test would leave a lot of hanging processes on the machine
541532
warn('The Global SDK E2E Install test cannot run as the machine is unprivileged.');
542533
}
534+
}
535+
536+
test('Install SDK Globally E2E (Requires Admin)', async () =>
537+
{
538+
await runGlobalSdkInstallTest('7.0.103');
539+
}).timeout(standardTimeoutTime * 1000);
540+
541+
test('Install SDK Globally with major version format', async () =>
542+
{
543+
await runGlobalSdkInstallTest('9');
544+
}).timeout(standardTimeoutTime * 1000);
545+
546+
test('Install SDK Globally with major minor format', async () =>
547+
{
548+
await runGlobalSdkInstallTest('10.0');
549+
}).timeout(standardTimeoutTime * 1000);
550+
551+
test('Install SDK Globally with feature band format', async () =>
552+
{
553+
await runGlobalSdkInstallTest('10.0.1xx');
543554
}).timeout(standardTimeoutTime * 1000);
544555

545556
test('Telemetry Sent During Install and Uninstall', async () =>
@@ -778,7 +789,7 @@ Paths: 'acquire returned: ${resultForAcquiringPathSettingRuntime.dotnetPath} whi
778789
assert.exists(result);
779790
assert.exists(result!.dotnetPath);
780791
assert.isTrue(fs.existsSync(result!.dotnetPath!));
781-
await promisify(rimraf)(result!.dotnetPath!);
792+
await fs.promises.rm(result!.dotnetPath!, { force: true });
782793
}
783794

784795
test('Install Runtime Status Command', async () =>

vscode-dotnet-runtime-extension/yarn.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vscode-dotnet-runtime-library/package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,22 @@ export function getMajorMinorFromValidVersion(fullySpecifiedVersion: string)
5555

5656
/**
5757
*
58-
* @param fullySpecifiedVersion the fully specified version, e.g. 7.0.301 to get the major minor from.
58+
* @param fullySpecifiedVersion the fully specified version, e.g. 7.0.301 to get the major minor from. Also accepts '8' and will assume a .0 minor.
5959
* @returns the major.minor in the form of '3.1', etc.
6060
*/
6161
export function getMajorMinor(fullySpecifiedVersion: string, eventStream: IEventStream, context: IAcquisitionWorkerContext): string
6262
{
6363
if (fullySpecifiedVersion.split('.').length < 2)
6464
{
65+
if (fullySpecifiedVersion.split('.').length === 0 && isNumber(fullySpecifiedVersion))
66+
{
67+
return `${fullySpecifiedVersion}.0`;
68+
}
69+
else if (fullySpecifiedVersion.split('.').length === 1 && isNumber(fullySpecifiedVersion.split('.')[0]))
70+
{
71+
return fullySpecifiedVersion;
72+
}
73+
6574
const event = new DotnetVersionResolutionError(new EventCancellationError('DotnetVersionResolutionError',
6675
`The requested version ${fullySpecifiedVersion} is invalid.`),
6776
getInstallFromContext(context));

0 commit comments

Comments
 (0)