-
-
Notifications
You must be signed in to change notification settings - Fork 106
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(install-env): Avoid automatic expansion of %%
in env
#44
Conversation
I think we can avoid making another function by just doing: function Get-Env {
param(
[String] $name,
[Switch] $global
)
$RegisterKey = if ($global) {
Get-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager'
} else {
Get-Item -Path 'HKCU:'
}
$EnvRegisterKey = $RegisterKey.OpenSubKey('Environment')
$RegistryValueOption = [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames
$EnvRegisterKey.GetValue($name, $null, $RegistryValueOption)
}
function Set-Env {
param(
[String] $name,
[String] $val,
[Switch] $global
)
$RegisterKey = if ($global) {
Get-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager'
} else {
Get-Item -Path 'HKCU:'
}
$EnvRegisterKey = $RegisterKey.OpenSubKey('Environment', $true)
$RegistryValueKind = if ($EnvRegisterKey.GetValue($name)) {
$EnvRegisterKey.GetValueKind($name)
} else {
[Microsoft.Win32.RegistryValueKind]::ExpandString
}
$EnvRegisterKey.SetValue($name, $val, $RegistryValueKind)
} |
Originally, I wanted to do the same, but the definition of RegisterKey was repeated. I think it was not good. At the same time, I don't want to add another parameter to the original |
|
Yes, there will be no interference between them, but I am just afraid that there will be a next revision, so the next revision will have to change two places, which doesn't look very good. No, what I mean by that sentence is to make All in all, hurry up and merge these two PRs. I don’t think there will be a better solution if we continue to discuss. Just choose a method that everyone agrees with. (I think the code you provided above is ok, as long as others think it's ok too.) |
Adding |
I'll review this in these two days. Thanks for the contribution. |
The implementation looks good to me. CI code linting failed because of the name of the newly introduced function. To fix it either change to use a verb that does not require |
%%
in env
|
I chose e.g., |
Use a method of obtaining environment variables that does not expand
%%
, while maintaining the original type of environment variables, such asREG_EXPAND_SZ
,REG_SZ
.Same issue related to ScoopInstaller/Scoop#5394
Some important content in ScoopInstaller/Scoop#5395