From 8fcb223d45edb87328e5cfe3cfa5b71bb0b037ec Mon Sep 17 00:00:00 2001 From: rami3l Date: Sun, 21 Apr 2024 19:41:59 +0800 Subject: [PATCH] refactor(self-update)!: remove confusing `get_path()` impl on Unix --- src/cli/self_update/test.rs | 21 +++++++-------------- src/test.rs | 4 ++-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/cli/self_update/test.rs b/src/cli/self_update/test.rs index 9c3a5bf60a..cf22644d77 100644 --- a/src/cli/self_update/test.rs +++ b/src/cli/self_update/test.rs @@ -26,18 +26,19 @@ pub fn with_saved_global_state( f(); } +#[cfg(windows)] pub fn with_saved_path(f: &mut dyn FnMut()) { - with_saved_global_state(get_path, restore_path, f) + with_saved_reg_value(&RegKey::predef(HKEY_CURRENT_USER), "Environment", "PATH", f) } -#[cfg(windows)] -pub fn get_path() -> io::Result> { - get_reg_value(&RegKey::predef(HKEY_CURRENT_USER), "Environment", "PATH") +#[cfg(unix)] +pub fn with_saved_path(f: &mut dyn FnMut()) { + f() } #[cfg(windows)] -fn restore_path(p: Option) { - restore_reg_value(&RegKey::predef(HKEY_CURRENT_USER), "Environment", "PATH", p) +pub fn get_path() -> io::Result> { + get_reg_value(&RegKey::predef(HKEY_CURRENT_USER), "Environment", "PATH") } #[cfg(windows)] @@ -70,11 +71,3 @@ fn restore_reg_value(root: &RegKey, subkey: &str, name: &str, p: Option io::Result> { - Ok(None) -} - -#[cfg(unix)] -fn restore_path(_: Option<()>) {} diff --git a/src/test.rs b/src/test.rs index c2ba40c57c..617b765cea 100644 --- a/src/test.rs +++ b/src/test.rs @@ -15,12 +15,12 @@ use std::process::Command; #[cfg(test)] use anyhow::Result; -pub use crate::cli::self_update::test::{get_path, with_saved_global_state, with_saved_path}; +pub use crate::cli::self_update::test::{with_saved_global_state, with_saved_path}; use crate::currentprocess; use crate::dist::dist::TargetTriple; #[cfg(windows)] -pub use crate::cli::self_update::test::with_saved_reg_value; +pub use crate::cli::self_update::test::{get_path, with_saved_reg_value}; // Things that can have environment variables applied to them. pub trait Env {