Automatically detect gsudo (#469)
This commit is contained in:
committed by
GitHub
parent
69b9c4b24c
commit
065565240e
@@ -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 {
|
||||
|
||||
@@ -14,7 +14,6 @@ pub struct ExecutionContext<'a> {
|
||||
}
|
||||
|
||||
impl<'a> ExecutionContext<'a> {
|
||||
#[cfg(unix)]
|
||||
pub fn new(
|
||||
run_type: RunType,
|
||||
sudo: &'a Option<PathBuf>,
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -87,9 +87,8 @@ pub fn which<T: AsRef<OsStr> + Debug>(binary_name: T) -> Option<PathBuf> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn sudo() -> Option<PathBuf> {
|
||||
which("sudo").or_else(|| which("pkexec"))
|
||||
which("sudo").or_else(|| which("gsudo")).or_else(|| which("pkexec"))
|
||||
}
|
||||
|
||||
pub fn editor() -> Vec<String> {
|
||||
|
||||
Reference in New Issue
Block a user