@@ -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+
472489interface 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