@@ -268,7 +268,7 @@ export class PowerShellExeFinder {
268
268
// Find the base directory for MSIX application exe shortcuts
269
269
const msixAppDir = path . join ( process . env . LOCALAPPDATA , "Microsoft" , "WindowsApps" ) ;
270
270
271
- if ( ! fs . existsSync ( msixAppDir ) ) {
271
+ if ( ! fileExistsSync ( msixAppDir ) ) {
272
272
return null ;
273
273
}
274
274
@@ -310,7 +310,13 @@ export class PowerShellExeFinder {
310
310
const powerShellInstallBaseDir = path . join ( programFilesPath , "PowerShell" ) ;
311
311
312
312
// 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 {
314
320
return null ;
315
321
}
316
322
@@ -469,6 +475,17 @@ export function getWindowsSystemPowerShellPath(systemFolderName: string) {
469
475
"powershell.exe" ) ;
470
476
}
471
477
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
+
472
489
interface IPossiblePowerShellExe extends IPowerShellExeDetails {
473
490
exists ( ) : boolean ;
474
491
}
@@ -491,7 +508,7 @@ class PossiblePowerShellExe implements IPossiblePowerShellExe {
491
508
492
509
public exists ( ) : boolean {
493
510
if ( this . knownToExist === undefined ) {
494
- this . knownToExist = fs . existsSync ( this . exePath ) ;
511
+ this . knownToExist = fileExistsSync ( this . exePath ) ;
495
512
}
496
513
return this . knownToExist ;
497
514
}
0 commit comments