From 6b6585245aafefce1a06cc35d5f7b6543698fe1d Mon Sep 17 00:00:00 2001 From: HUMORCE Date: Mon, 19 Jun 2023 21:52:59 +0000 Subject: [PATCH 1/5] fix(core): Check if the envrionment variable exists before delete --- lib/core.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index 3b66654b97..936dfec161 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -698,7 +698,7 @@ function env($name, $global, $val = '__get') { $RegistryValueOption = [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames $EnvRegisterKey.GetValue($name, $null, $RegistryValueOption) } elseif ($val -eq $null) { - $EnvRegisterKey.DeleteValue($name) + if ($EnvRegisterKey.GetValue($name)) { $EnvRegisterKey.DeleteValue($name) } } else { $RegistryValueKind = if ($val.Contains('%')) { [Microsoft.Win32.RegistryValueKind]::ExpandString From 8387ab9cbd797dc3a81f79a76ba4f7a15f2ab5d0 Mon Sep 17 00:00:00 2001 From: HUMORCE Date: Mon, 19 Jun 2023 22:11:32 +0000 Subject: [PATCH 2/5] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bcc94c162..8fc2eac8cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - **scoop-info:** Fix errors in file size collection when `--verbose` ([#5352](https://github.com/ScoopInstaller/Scoop/pull/5352)) - **shim:** Use bash executable directly ([#5433](https://github.com/ScoopInstaller/Scoop/issues/5433)) - **scoop-checkup:** Skip defender check in Windows Sandbox ([#5519]https://github.com/ScoopInstaller/Scoop/issues/5519) +- **fix(core):** Check if the envrionment variable exists before deletion ([#5547]https://github.com/ScoopInstaller/Scoop/issues/5547) ### Performance Improvements From fa3878319b9e736aa7796258e075fe9c1ef58fc3 Mon Sep 17 00:00:00 2001 From: HUMORCE Date: Mon, 19 Jun 2023 22:29:42 +0000 Subject: [PATCH 3/5] Use `try, catch`, value of env variable may is null/empty --- lib/core.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index 936dfec161..41802e506b 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -698,7 +698,7 @@ function env($name, $global, $val = '__get') { $RegistryValueOption = [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames $EnvRegisterKey.GetValue($name, $null, $RegistryValueOption) } elseif ($val -eq $null) { - if ($EnvRegisterKey.GetValue($name)) { $EnvRegisterKey.DeleteValue($name) } + try { $EnvRegisterKey.DeleteValue($name) } catch { } } else { $RegistryValueKind = if ($val.Contains('%')) { [Microsoft.Win32.RegistryValueKind]::ExpandString From fa4f56cf2d73b5aa77d63d753e142974303684ec Mon Sep 17 00:00:00 2001 From: HUMORCE Date: Mon, 19 Jun 2023 22:56:11 +0000 Subject: [PATCH 4/5] UPDATE CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fc2eac8cf..9f6e2081b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ - **scoop-info:** Fix errors in file size collection when `--verbose` ([#5352](https://github.com/ScoopInstaller/Scoop/pull/5352)) - **shim:** Use bash executable directly ([#5433](https://github.com/ScoopInstaller/Scoop/issues/5433)) - **scoop-checkup:** Skip defender check in Windows Sandbox ([#5519]https://github.com/ScoopInstaller/Scoop/issues/5519) -- **fix(core):** Check if the envrionment variable exists before deletion ([#5547]https://github.com/ScoopInstaller/Scoop/issues/5547) +- **fix(core):** Avoid error messages when deleting non-existent environment variable ([#5547]https://github.com/ScoopInstaller/Scoop/issues/5547) ### Performance Improvements From 106d85676a083d43f6edf584d53020c0c3f1794f Mon Sep 17 00:00:00 2001 From: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> Date: Tue, 3 Oct 2023 16:28:51 +0530 Subject: [PATCH 5/5] Brackets --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5f4dfe3b9..2557311c4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ - **install:** Fix download from private GitHub repositories ([#5361](https://github.com/ScoopInstaller/Scoop/issues/5361)) - **scoop-info:** Fix errors in file size collection when `--verbose` ([#5352](https://github.com/ScoopInstaller/Scoop/pull/5352)) - **shim:** Use bash executable directly ([#5433](https://github.com/ScoopInstaller/Scoop/issues/5433)) -- **core:** Avoid error messages when deleting non-existent environment variable ([#5547]https://github.com/ScoopInstaller/Scoop/issues/5547) +- **core:** Avoid error messages when deleting non-existent environment variable ([#5547](https://github.com/ScoopInstaller/Scoop/issues/5547)) - **core:** Use relative path as fallback of `$scoopdir` ([#5544](https://github.com/ScoopInstaller/Scoop/issues/5544)) - **scoop-checkup:** Skip defender check in Windows Sandbox ([#5519](https://github.com/ScoopInstaller/Scoop/issues/5519)) - **buckets:** Avoid error messages for unexpected dir ([#5549](https://github.com/ScoopInstaller/Scoop/issues/5549))