Skip to content

Commit

Permalink
Update to handle PS Core binary name change
Browse files Browse the repository at this point in the history
Fix PowerShell#1064

Also fixes case where the powerShellExePath setting is no longer valid.  This happens when a Windows users installs an updated pre-release version of PS Core.  That uninstalls previous versions.
  • Loading branch information
rkeithhill committed Oct 26, 2017
1 parent ccebc4d commit 8d3ff45
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ export function getDefaultPowerShellPath(
}
else if (platformDetails.operatingSystem == OperatingSystem.MacOS) {
powerShellExePath = "/usr/local/bin/powershell";
if (fs.existsSync("/usr/loca/bin/pwsh")) {
powerShellExePath = "/usr/local/bin/pwsh";
}
}
else if (platformDetails.operatingSystem == OperatingSystem.Linux) {
powerShellExePath = "/usr/bin/powershell";
if (fs.existsSync("/usr/bin/pwsh")) {
powerShellExePath = "/usr/bin/pwsh";
}
}

return powerShellExePath;
Expand Down Expand Up @@ -146,9 +152,14 @@ export function getAvailablePowerShellExes(platformDetails: PlatformDetails): Po
.map(item => path.join(psCoreInstallPath, item))
.filter(item => fs.lstatSync(item).isDirectory())
.map(item => {
let exePath = path.join(item, "pwsh.exe");
if (!fs.existsSync(exePath)) {
exePath = path.join(item, "powershell.exe");
}

return {
versionName: `PowerShell Core ${path.parse(item).base}`,
exePath: path.join(item, "powershell.exe")
exePath: exePath
};
});

Expand All @@ -158,12 +169,10 @@ export function getAvailablePowerShellExes(platformDetails: PlatformDetails): Po
}
}
else {

paths.push({
versionName: "PowerShell Core",
exePath:
os.platform() === "darwin"
? "/usr/local/bin/powershell"
: "/usr/bin/powershell"
exePath: this.getDefaultPowerShellPath(platformDetails)
});
}

Expand Down
8 changes: 8 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,14 @@ export class SessionManager implements Middleware {
this.sessionSettings.developer.powerShellExePath ||
"").trim();

// New versions of PS Core uninstall the previous version
// so make sure the path stored in the settings exists.
if (!fs.existsSync(powerShellExePath)) {
this.log.write(
`Path specified by 'powerShellExePath' setting - '${powerShellExePath}' - not found, reverting to default PowerShell path.`);
powerShellExePath = "";
}

if (this.platformDetails.operatingSystem === OperatingSystem.Windows &&
powerShellExePath.length > 0) {

Expand Down

0 comments on commit 8d3ff45

Please sign in to comment.