Fix PATH behavior of non-symlink installations for Portables/Zip
Fixes:
- #2909
- #2949
Description:
When failing to create a symlink (non-developer mode or non-admin), we should be adding the package install directory directly to PATH. However, the default root directory for portable packages was always being added instead. This has been causing issues when users attempt to execute the command alias, which fails to recognize the portable executable/symlink. This is especially problematic for portable(s) in zips as their RelativeFilePath was being ignored.
Changes:
- If we fail to create a symlink, the InstallDirectoryAddedToPath key value is set to true and the portable target directory is added directly to PATH for all portables.
- Modified the AddToPathVariable method to take in a value to add to PATH instead of predetermining the value to add to the PATH registry. This allows for multiple values to be appended to PATH to support multiple portables in an archive scenario.
- Installing portable from zip always write to index. Previously, there was a check to see if there was greater than 1 item in the archive before writing to the index, but this is actually a bug because it could point to a single directory. The index is also a better way to keep track of all the files that were added.
Tests:
- Modified the SymlinkCreationFail unit tests to point to a temporary install location and verified that the temp install location is properly appended to the PATH registry during install and removed during uninstall.
- Verified that the changes could successfully install and uninstall
ffmpegwhich was the example identified in the issues above.
Microsoft Reviewers: Open in CodeFlow
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
Path environment variable modified; restart your shell to use the new value.
how to restart your shell to use the new value?
how to restart your shell to use the new value?
Basically, to make the console (you are using) recognize newly added env variables, you'll have to restart it. For example, if you are running winget in Powershell, just close and start a new Powershell window. Only new instances of Powershell will recognize new portable added by winget. Same for CMD, WindowsTerminal, etc.