-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
[core] (Windows) Remove all Machine
PATH handling, add safety mechanisms
#957
Conversation
Sounds good from the PR description. I suppose I should volunteer to test this one myself some time, but will be busy with Regular release today I think. But if I haven't come back to test this and no-one else has, feel free to ping and request it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubber-stamp approve in case I don't get time to test this properly.
EDIT: I am going to attempt to test this right now, though, will see how far I get with it. Reporting back soon if all goes well.
Well, I do get an error / stack trace:
Full stack trace (click to expand):
This is referring to So, maybe the error happens when there is no per-user install, only a system-wide ( |
Alright, for anyone that's willing to give this a review, especially @DeeDeeG since you've already taken a look, I've gone ahead and fixed the issues present, and tested this more thoroughly. The issue you first encountered was me simply forgetting to remove a reference to a now non-existent variable. Otherwise I've also opted to log the users current PATH only when logging the path, meanwhile previously we were appending to the file. The reason I added the reboot, and a warning to anyone who tests, when you add Pulsar to the PATH in this script, it adds it to the Windows Registry, which doesn't immediately populate the current shell value, meaning that right away you can't use But this also means that Pulsar is unable to remove it until it's shell session has been restarted, which it seems that NodeJS must cache this info somewhere, because I had to fully restart All of this will be taken care of though if users have restarted between turning this setting on and turning it off, which should be rather common I'd think. |
I might be barking up the wrong tree with this suggestion, but would it be possible to use something like
And to detect if the PATH string we want to add is already present, maybe scan the current 🤔 |
src/main-process/win-shell.js
Outdated
`"${pulsarPath}\\resources\\modifyWindowsPath.ps1"`, | ||
['-installdir', `"${pulsarPath}"`, '-remove', '0'], | ||
`powershell.exe '${pulsarPath}\\resources\\modifyWindowsPath.ps1'`, | ||
['-installdir', `'${pulsarPath}'`, '-remove', '0'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing this, I was going to report that this wasn't working for me in testing, but I felt bad just reporting "it didn't work for me" and another stack trace, so I was looking into it further.
I got a bit stumped about the right way forward though, something about the quoting vs the `` template string stuff but wasn't sure how much you'd already tried and ruled out. Heh.
Hopefully I'll be able to test this latest revision soon and report back.
Also, in some quick testing, the checkbox didn't seem to want to do anything if I had a system-wide install that I wanted on my per-user PATH. It strikes me as reasonable to install once system-wide, and want that copy added to my PATH some way or other. I hope that's doable, I might have misunderstood since I haven't dived deep into the code for this yet. |
@DeeDeeG Alright, that's my bad, seems I didn't test Machine handling as thoroughly as I thought. Things should now be functional. Seems there was issues because the installation location of Pulsar was being detected via it's registry entry, which on this rewrite only ever checks the current user's registry, which of course has no entry for Pulsar for a machine install, so Pulsar wasn't able to find the installation location on machine installs to provide when setting it's value in the PATH. But to clarify on expected behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I finally managed to test all configurations.
- System-wide and per-user installs, add to path from per-user install: Works. ✅ Launches the per-user install.
- System-wide and per-user installs, add to path from system-wide install: Works. ✅ Launches the system-wide install.
- System-wide install only:
⚠️ Error message in console? (Something about permission denied to access a.txt
file living underC:\Program Files\Pulsar\ . . .
, see full error message below...) But still works. ✅ - Per-user install only: Works. ✅
Note: All tested scenarios did appear to require a restart for the cmd.exe
to load the new PATH entries and have pulsar --version
and where pulsar
work, which is just as the message says below the checkbox in the Pulsar settings-view UI for this preference.
The error message in console when adding the system-wide install to PATH was this:
Add Pulsar to PATH:
C:\Users\user\Downloads\Pulsar-1.115.2024032609-win\resources\app.asar\src\main-process\win-shell.js:132 stdout:
C:\Users\user\Downloads\Pulsar-1.115.2024032609-win\resources\app.asar\src\main-process\win-shell.js:133 stderr: out-file : Access to the path 'C:\Program Files\Pulsar\prior2addition.txt' is denied.
At C:\Users\user\AppData\Local\Programs\Pulsar\resources\modifyWindowsPath.ps1:28 char:3
+ $env:Path > prior2addition.txt;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Out-File], UnauthorizedAccessException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
(From C:\Users\user\Downloads\Pulsar-1.115.2024032609-win\resources\app.asar\src\main-process\win-shell.js:133)
(Tangent: I don't know why DevTools thinks the JS file being run was loaded from my Downloads folder, I launched portable Pulsar from that path once and have since moved it to a different location several reboots ago, DevTools are just confused. The JS file doesn't even exist at that path anymore... What the heck DevTools?)
Side note about a potential "weird user experience" edge case: I also got an error when trying to re-add it after manually removing the PATH entries in Windows' env var editing UI without rebooting first. It said "Pulsar is already on the PATH" in the dev tools. Which was probably true if consulting the registry, but not true if checking the active PATH entries one could see in cmd.exe. So, users may find his unintuitive, but the solution is to reboot and then check if it's actually in the PATH, if not then re-add and it should work. And implicit in this solution is: Don't manually mess with the PATH entries if you don't have to, as an end-user of Pulsar trying to use the "Add to PATH" UI checkbox in Pulsar's settings-view.
I found the code somewhat intimidating to look through and review, so I'm not planning on doing that. Approving on the basis of it's tested and working. 👍
However, some time in the future, if it's possible to avoid messing with the registry, rebooting, etc. etc. etc., and drastically simplify the code, perhaps by calling setx
instead, I would highly recommend a simplified approach for reliability, readability, and potentially better user experience, assuming the implementation as I'm envisioning it is in fact possible, which is not a given.
In any case, thanks for all the work on improving this!
Thanks a ton for the review! With that I'll probably want to merge this, but will address some of the points you brought up and leave it open for a tad longer in case there's anything you'd want to respond to with that, but otherwise no need to. But as for the error message you see about access denied, that part is expected, I did see it in testing and should've called it out. But when we now mess with the PATH we try and save a copy of the users path to Pulsar's As for reboots. This one may be possible to fix in the future. Essentially when a shell in Windows is started, it "caches" the machine and user path values (along with other stuff) and uses that when running. This means that the values in the registry could change, but that shell session wouldn't be aware of it. Finally your comment on |
Okay, sounds well thought out. I especially didn't realize (There are profound pros and cons to Windows not breaking a lot of its low-level stuff from decades ago... I guess one of them is CLI tools literally from another decade or several ago having weird limits that aren't that relevant to modern hardware.)
It could be put somewhere in the |
Also: It was possible to add multiple copies of the Pulsar paths to the PATH. I didn't reverse-engineer the exact steps to reproduce, though. It might be checking the box multiple times in a row before ever re-booting? EDIT: I don't think this is a huge deal, since "searching the same paths for bins multiple times" wouldn't really have any adverse effects that I'm aware of. It's simply unexpected and adds a slight amount of clutter and extra length to the PATH. |
If there are any improvements possible, I am quite sure we can do them as follow-ups. So, no reason not to merge. Thank you! |
As we have seen, there have been a few reported issues of dealing with the
Machine
PATH in Pulsar. These issues stemming from:For all of the above reasons, it seems like a fair trade-off to stop attempting to manage the Machine PATH at all, and instead opt to only ever modify the User PATH. This does mean that Pulsar installed on a shared machine will require each user to enable Pulsar on their user profiles PATH, but if anything that almost makes complete sense to me, rather than Pulsar trying to ensure it's on everyone's PATH.
As such, removing this handling allowed much simply logic both in terms of displaying these UI elements, and the logic for controlling how the PowerShell script is started.
Even further it allows the PowerShell script to be much simpler, and faster, by removing any self-elevation logic, and pseudo progress bars.
Beyond that, I've ensured to add additional safety features here, such as much more clearly ensuring to not modify the PATH if we have already done it, saving a copy of the users path prior to any modification, and overall studying how other older programs handle this logic (namely Chocolatey).
From here, the only real downside that I can find within this code is that we don't handle auto expanding variables within the user's path. Which is (as far as I can tell) an uncommon use-case, and something we can't easily get around, since getting around this requires much more complex calls, and a more direct manipulation of the registry, which then brings in other issues we have to worry about like character limits, etc. So this seems like a fine trade off.
Additional testing should be required prior to merging, specifically I'd be most curious about behavior on uncommon installation locations, and various machine installs, which over the next couple of days I'll do my best to get around to.
Fixes #816