diff --git a/src/config.rs b/src/config.rs index 3ca481c6..30c24cc2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -385,6 +385,15 @@ impl Config { check_deprecated!(config_file, yay_arguments, linux, yay_arguments); check_deprecated!(config_file, accept_all_windows_updates, windows, accept_all_updates); + if config_file + .windows + .as_ref() + .map(|w| w.use_gsudo_with_choco.is_some()) + .unwrap_or(false) + { + println!("use_gsudo_with_choco is deprecated and will be removed in the future. Topgrade will not automatically detect and use gsudo"); + } + let allowed_steps = Self::allowed_steps(&opt, &config_file); Ok(Self { @@ -526,16 +535,6 @@ impl Config { .unwrap_or(false) } - /// Whether to use gsudo command with choco if available - #[allow(dead_code)] - pub fn use_gsudo_with_choco(&self) -> bool { - self.config_file - .windows - .as_ref() - .and_then(|w| w.use_gsudo_with_choco) - .unwrap_or(false) - } - /// Whether Brew cask should be greedy #[allow(dead_code)] pub fn brew_cask_greedy(&self) -> bool { diff --git a/src/execution_context.rs b/src/execution_context.rs index f1ef10fd..1d3b2182 100644 --- a/src/execution_context.rs +++ b/src/execution_context.rs @@ -14,7 +14,6 @@ pub struct ExecutionContext<'a> { } impl<'a> ExecutionContext<'a> { - #[cfg(unix)] pub fn new( run_type: RunType, sudo: &'a Option, @@ -31,17 +30,6 @@ impl<'a> ExecutionContext<'a> { } } - #[cfg(not(unix))] - pub fn new(run_type: RunType, git: &'a Git, config: &'a Config, base_dirs: &'a BaseDirs) -> ExecutionContext<'a> { - ExecutionContext { - run_type, - sudo: &None, - config, - git, - base_dirs, - } - } - pub fn run_type(&self) -> RunType { self.run_type } diff --git a/src/main.rs b/src/main.rs index 103f7ac4..f6edf2b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,16 +65,11 @@ fn run() -> Result<()> { let git = git::Git::new(); let mut git_repos = git::Repositories::new(&git); - #[cfg(unix)] let sudo = utils::sudo(); let run_type = executor::RunType::new(config.dry_run()); - #[cfg(unix)] let ctx = execution_context::ExecutionContext::new(run_type, &sudo, &git, &config, &base_dirs); - #[cfg(not(unix))] - let ctx = execution_context::ExecutionContext::new(run_type, &git, &config, &base_dirs); - let mut runner = runner::Runner::new(&ctx); #[cfg(feature = "self-update")] diff --git a/src/steps/os/windows.rs b/src/steps/os/windows.rs index 04315010..6e401400 100644 --- a/src/steps/os/windows.rs +++ b/src/steps/os/windows.rs @@ -3,26 +3,22 @@ use crate::execution_context::ExecutionContext; use crate::executor::{CommandExt, RunType}; use crate::powershell; use crate::terminal::print_separator; -use crate::utils::{require, which}; +use crate::utils::require; use anyhow::Result; use std::process::Command; pub fn run_chocolatey(ctx: &ExecutionContext) -> Result<()> { let choco = require("choco")?; let yes = ctx.config().yes(); - let use_gsudo = ctx.config().use_gsudo_with_choco(); print_separator("Chocolatey"); - let mut cmd = choco; + let mut cmd = &choco; let mut args = vec!["upgrade", "all"]; - if use_gsudo { - let gsudo = which("gsudo"); - if let Some(gsudo) = gsudo { - cmd = gsudo; - args = vec!["choco", "upgrade", "all"]; - } + if let Some(sudo) = ctx.sudo() { + cmd = sudo; + args.insert(0, "choco"); } let mut command = ctx.run_type().execute(&cmd); diff --git a/src/utils.rs b/src/utils.rs index ad68129f..26171632 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -87,9 +87,8 @@ pub fn which + Debug>(binary_name: T) -> Option { } } -#[cfg(unix)] pub fn sudo() -> Option { - which("sudo").or_else(|| which("pkexec")) + which("sudo").or_else(|| which("gsudo")).or_else(|| which("pkexec")) } pub fn editor() -> Vec {