Skip to content

Resolve $Linux error #1235

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

Merged
merged 2 commits into from
Mar 22, 2018
Merged

Resolve $Linux error #1235

merged 2 commits into from
Mar 22, 2018

Conversation

dsolodow
Copy link
Contributor

This resolves #996.

Tested on:
Windows 10 x64 Education Build 17127 (Windows PowerShell 5.1)
Windows 10 x64 Education Build 17127 (PowerShell Core 6.0.2)
Ubuntu 16.04 (PowerShell Core 6.0.2)

@TylerLeonhardt
Copy link
Member

@dsolodow you're on FIRE🔥 today. This looks fine to me although I'm not sure if $env:windir -ne $null applies in older versions of PowerShell since we technically still support PS 3 and up.

What you could do is take advantage of the $IsWindows variable in PSCore.

If it's True or null (which would mean it's Windows PowerShell), then we can do the logic.

Just a thought.

@dsolodow
Copy link
Contributor Author

@tylerl0706 - good point.
The $env:windir -ne $null works as far back as Windows PowerShell 2.0 (just verified it on a Server 2008 R2 box).

I had originally thought about doing something with psversiontable (psedition and platform) but it was going to be fuglier. I didn't know about the $IsWindows as I've not dipped my toes much into PSCore yet.

It would be easy enough to switch over if that's preferred by the team.

@rjmholt
Copy link
Contributor

rjmholt commented Mar 21, 2018

Was going to say $IsWindows would be more readable, but tbh (($IsWindows -eq $null) -or $IsWindows) is pretty mystifying. The only advantage is that if someone defines export windir="something" on a Unix-like system, they break the $env:windir check.

@rjmholt
Copy link
Contributor

rjmholt commented Mar 21, 2018

So I'm happy with either too

@@ -129,7 +131,7 @@ param(
[switch]$LaunchWhenDone
)

if (!($IsLinux -or $IsOSX)) {
if ($env:windir -ne $null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For this kind of test, I usually use if (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) { i.e. if the platform is <= v5 then it is Windows. If it is v6 or higher then $IsWindows will be set appropriately. But there are several different ways to do this check that is valid across versions & platforms.

I prefer the above test because it uses PowerShell built-in variables. Env vars are controlled by the user and there is nothing stopping a Linux/macOS user from defining a windir env var.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that seems like the right way to test this

Copy link
Member

Choose a reason for hiding this comment

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

Yep makes sense. The bug was opened because of StrictMode and I think what Keith said should play nice with it as well.

Change test for "isWindows"
@dsolodow
Copy link
Contributor Author

That makes sense; fewer opportunities for someone to do something wonky in their environment and break it. :)
I've updated the check, and tested it on:
Windows 10 x64 Education (Build 17063) (Windows PowerShell)
Windows 10 x64 Education (Build 17063) (PowerShell Core 6.0.2)
Ubuntu 16.04 (PowerShell Core 6.0.2)
Windows Server 2008R2 SP1 (Windows PowerShell 2.0)

Copy link
Contributor

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

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

LGTM

@TylerLeonhardt
Copy link
Member

merge time 😎

@TylerLeonhardt TylerLeonhardt merged commit 63d8204 into PowerShell:master Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vscode-powershell / scripts / Install-VSCode.ps1 $IsLinux failure
4 participants