Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PowerShell MSIX (Store) detection #3202

Merged
merged 1 commit into from
Feb 25, 2021

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Feb 23, 2021

PR Summary

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.

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets.
Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
  • Summarized changes
  • PR has tests
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

@ghost ghost added Area-Startup Issue-Bug A bug to squash. labels Feb 23, 2021
@@ -268,7 +268,7 @@ export class PowerShellExeFinder {
// Find the base directory for MSIX application exe shortcuts
const msixAppDir = path.join(process.env.LOCALAPPDATA, "Microsoft", "WindowsApps");

if (!fs.existsSync(msixAppDir)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call to remove this anyway:

fs.existsSync() will be deprecated.

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

function fileExistsSync(filePath: string): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The node docs aren't wrong about this kinda being an anti-pattern.

fs.exists() is an anachronism and exists only for historical reasons. There should almost never be a reason to use it in your own code.

In particular, checking if a file exists before opening it is an anti-pattern that leaves you vulnerable to race conditions: another process may remove the file between the calls to fs.exists() and fs.open(). Just open the file and handle the error when it's not there.

fs.exists() will be deprecated.

We're essentially making our own fs.existsSync and I question if we need it. As the code is written right now, this does seem to be the best option, but I'd want to review why we're checking if a file exists, then checking if a folder exists, etc.

try {
// This will throw if the path does not exist,
// and otherwise returns a value that we don't care about
fs.lstatSync(filePath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably ought to just be fs.statSync since we don't care about the information, but we may care that the target file exists. I don't really care though, as the code as written is (presumably) tested, and it's not really our problem if the symlink exists but its target does not.

Copy link
Member

@andyleejordan andyleejordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we'll make it any worse 😂

@andyleejordan andyleejordan merged commit f226597 into PowerShell:master Feb 25, 2021
@andyleejordan
Copy link
Member

Weird, @rjmholt the CI tests passed on this PR but then failed on the merge to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

microsoft store installed powershell can not be recognized
2 participants