Skip to content

Commit

Permalink
refactor(self-update)!: remove confusing get_path() impl on Unix
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Apr 21, 2024
1 parent 3dee2da commit a6c9fae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
21 changes: 7 additions & 14 deletions src/cli/self_update/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ pub fn with_saved_global_state<S>(
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<Option<RegValue>> {
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<RegValue>) {
restore_reg_value(&RegKey::predef(HKEY_CURRENT_USER), "Environment", "PATH", p)
pub fn get_path() -> io::Result<Option<RegValue>> {
get_reg_value(&RegKey::predef(HKEY_CURRENT_USER), "Environment", "PATH")
}

#[cfg(windows)]
Expand Down Expand Up @@ -70,11 +71,3 @@ fn restore_reg_value(root: &RegKey, subkey: &str, name: &str, p: Option<RegValue
let _ = subkey.delete_value(name);
}
}

#[cfg(unix)]
pub fn get_path() -> io::Result<Option<()>> {
Ok(None)
}

#[cfg(unix)]
fn restore_path(_: Option<()>) {}
4 changes: 2 additions & 2 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a6c9fae

Please sign in to comment.