Skip to content

Commit f226597

Browse files
authored
Fix PowerShell MSIX (Store) detection (#3202)
Fixes #3181. The MSIX exe is a symlink and node's file test API returns false for those. This fixes that so we now detect the PowerShell MSIX installation properly again.
1 parent 65b3231 commit f226597

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/platform.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export class PowerShellExeFinder {
268268
// Find the base directory for MSIX application exe shortcuts
269269
const msixAppDir = path.join(process.env.LOCALAPPDATA, "Microsoft", "WindowsApps");
270270

271-
if (!fs.existsSync(msixAppDir)) {
271+
if (!fileExistsSync(msixAppDir)) {
272272
return null;
273273
}
274274

@@ -310,7 +310,13 @@ export class PowerShellExeFinder {
310310
const powerShellInstallBaseDir = path.join(programFilesPath, "PowerShell");
311311

312312
// Ensure the base directory exists
313-
if (!(fs.existsSync(powerShellInstallBaseDir) && fs.lstatSync(powerShellInstallBaseDir).isDirectory())) {
313+
try {
314+
const powerShellInstallBaseDirLStat = fs.lstatSync(powerShellInstallBaseDir);
315+
if (!powerShellInstallBaseDirLStat.isDirectory())
316+
{
317+
return null;
318+
}
319+
} catch {
314320
return null;
315321
}
316322

@@ -469,6 +475,17 @@ export function getWindowsSystemPowerShellPath(systemFolderName: string) {
469475
"powershell.exe");
470476
}
471477

478+
function fileExistsSync(filePath: string): boolean {
479+
try {
480+
// This will throw if the path does not exist,
481+
// and otherwise returns a value that we don't care about
482+
fs.lstatSync(filePath);
483+
return true;
484+
} catch {
485+
return false;
486+
}
487+
}
488+
472489
interface IPossiblePowerShellExe extends IPowerShellExeDetails {
473490
exists(): boolean;
474491
}
@@ -491,7 +508,7 @@ class PossiblePowerShellExe implements IPossiblePowerShellExe {
491508

492509
public exists(): boolean {
493510
if (this.knownToExist === undefined) {
494-
this.knownToExist = fs.existsSync(this.exePath);
511+
this.knownToExist = fileExistsSync(this.exePath);
495512
}
496513
return this.knownToExist;
497514
}

0 commit comments

Comments
 (0)