Skip to content

Commit 9e31011

Browse files
authored
Merge pull request #1612 from nagilson/nagilson-fix-package-mixups
Use Installer Type Conforming Installation Directory for Ubuntu
2 parents d286da8 + bbd4d6b commit 9e31011

6 files changed

Lines changed: 48 additions & 4 deletions

File tree

vscode-dotnet-runtime-library/distro-data/distro-support.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,16 @@
5959
"commandParts": ["-l", "{packageName}"]
6060
}
6161
],
62+
"readSymLinkCommand":
63+
[
64+
{
65+
"runUnderSudo": false,
66+
"commandRoot": "readlink",
67+
"commandParts": ["-f", "{path}"]
68+
}
69+
],
6270
"expectedDistroFeedInstallDirectory" : "/usr/lib/dotnet",
63-
"expectedMicrosoftFeedInstallDirectory" : "/usr/bin/dotnet",
71+
"expectedMicrosoftFeedInstallDirectory" : "/usr/share/dotnet",
6472
"installedSDKVersionsCommand":
6573
[
6674
{
@@ -255,6 +263,14 @@
255263
]
256264
}
257265
],
266+
"readSymLinkCommand":
267+
[
268+
{
269+
"runUnderSudo": false,
270+
"commandRoot": "readlink",
271+
"commandParts": ["-f", "{path}"]
272+
}
273+
],
258274
"expectedDistroFeedInstallDirectory": "/usr/lib64/dotnet/dotnet",
259275
"expectedMicrosoftFeedInstallDirectory": "",
260276
"installedSDKVersionsCommand": [

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { IDistroDotnetSDKProvider } from './IDistroDotnetSDKProvider';
1313

1414
export class GenericDistroSDKProvider extends IDistroDotnetSDKProvider
1515
{
16+
protected resolvePathAsSymlink = true;
17+
1618
public async installDotnet(fullySpecifiedVersion : string, installType : LinuxInstallType): Promise<string>
1719
{
1820
await this.injectPMCFeed(fullySpecifiedVersion, installType);
@@ -37,6 +39,18 @@ export class GenericDistroSDKProvider extends IDistroDotnetSDKProvider
3739
{
3840
commandResult[0] = commandResult[0].trim();
3941
}
42+
43+
if(commandResult && this.resolvePathAsSymlink)
44+
{
45+
let symLinkReadCommand = this.myDistroCommands(this.readSymbolicLinkCommandKey);
46+
symLinkReadCommand = CommandExecutor.replaceSubstringsInCommands(symLinkReadCommand, this.missingPathKey, commandResult[0]);
47+
const resolvedPath = (await this.commandRunner.executeMultipleCommands(symLinkReadCommand))[0];
48+
if(resolvedPath)
49+
{
50+
return path.dirname(resolvedPath.trim());
51+
}
52+
}
53+
4054
return commandResult[0];
4155
}
4256

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export abstract class IDistroDotnetSDKProvider {
4343
protected searchCommandKey = 'searchCommand';
4444
protected updateCommandKey = 'updateCommand';
4545
protected packageLookupCommandKey = 'packageLookupCommand';
46+
protected readSymbolicLinkCommandKey = 'readSymLinkCommand';
4647
protected currentInstallPathCommandKey = 'currentInstallPathCommand';
4748
protected isInstalledCommandKey = 'isInstalledCommand';
4849
protected expectedMicrosoftFeedInstallDirKey = 'expectedMicrosoftFeedInstallDirectory';
@@ -51,6 +52,7 @@ export abstract class IDistroDotnetSDKProvider {
5152
protected installedRuntimeVersionsCommandKey = 'installedRuntimeVersionsCommand';
5253
protected currentInstallVersionCommandKey = 'currentInstallationVersionCommand';
5354
protected missingPackageNameKey = '{packageName}';
55+
protected missingPathKey = '{path}';
5456

5557
protected distroVersionsKey = 'versions';
5658
protected versionKey = 'version';

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@
33
* The .NET Foundation licenses this file to you under the MIT license.
44
* Licensed under the MIT License. See License.txt in the project root for license information.
55
* ------------------------------------------------------------------------------------------ */
6+
import { ICommandExecutor } from '../Utils/ICommandExecutor';
7+
import { IUtilityContext } from '../Utils/IUtilityContext';
68
import { GenericDistroSDKProvider } from './GenericDistroSDKProvider';
9+
import { IAcquisitionWorkerContext } from './IAcquisitionWorkerContext';
710
import { LinuxInstallType } from './LinuxInstallType';
11+
import { DistroVersionPair } from './LinuxVersionResolver';
812
/* tslint:disable:no-any */
913

1014
export class RedHatDistroSDKProvider extends GenericDistroSDKProvider
1115
{
16+
constructor(distroVersion : DistroVersionPair, context : IAcquisitionWorkerContext, utilContext : IUtilityContext, executor : ICommandExecutor | null = null)
17+
{
18+
super(distroVersion, context, utilContext, executor);
19+
this.resolvePathAsSymlink = false;
20+
}
21+
1222
protected myVersionDetails() : any
1323
{
1424
const distroVersions = this.distroJson[this.distroVersion.distro][this.distroVersionsKey];

vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ Please install the .NET SDK manually by following https://learn.microsoft.com/en
8686
return new Promise<string>((resolve, reject) =>
8787
{
8888
// The '.' character is not allowed for sudo-prompt so we use 'NET'
89-
const options = { name: `${this.context?.acquisitionContext?.requestingExtensionId} On behalf of NET Install Tool` };
89+
let sanitizedCallerName = this.context?.acquisitionContext?.requestingExtensionId?.replace(/[^0-9a-z]/gi, ''); // Remove non-alphanumerics per OS requirements
90+
sanitizedCallerName = sanitizedCallerName?.substring(0, 69); // 70 Characters is the maximum limit we can use for the prompt.
91+
const options = { name: `${sanitizedCallerName ?? '.NET Install Tool'}` };
9092
exec((fullCommandString), options, (error?: any, stdout?: any, stderr?: any) =>
9193
{
9294
let commandResultString = '';

vscode-dotnet-runtime-library/src/test/unit/LinuxDistroTests.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ suite('Linux Distro Logic Unit Tests', () =>
6161
if(shouldRun)
6262
{
6363
const microsoftFeedDir = await provider.getExpectedDotnetMicrosoftFeedInstallationDirectory();
64-
assert.equal(microsoftFeedDir, '/usr/bin/dotnet');
64+
assert.equal(microsoftFeedDir, '/usr/share/dotnet');
6565
}
6666
}).timeout(standardTimeoutTime);
6767

@@ -104,7 +104,7 @@ Microsoft.NETCore.App 7.0.5 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]`;
104104
if(shouldRun)
105105
{
106106
await provider.getInstalledGlobalDotnetPathIfExists(installType);
107-
assert.equal(mockExecutor.attemptedCommand, 'which dotnet');
107+
assert.equal(mockExecutor.attemptedCommand, 'readlink -f /usr/bin/dotnet');
108108
}
109109
}).timeout(standardTimeoutTime);
110110

0 commit comments

Comments
 (0)