fix(sudo): use require_sudo for windows commands
This commit is contained in:
@@ -1081,7 +1081,7 @@ pub fn run_powershell(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
// and Update-Module updates all modules regardless of their original installation scope
|
// and Update-Module updates all modules regardless of their original installation scope
|
||||||
powershell.build_command(ctx, &cmd, false)?.status_checked()
|
powershell.build_command(ctx, &cmd, false)?.status_checked()
|
||||||
} else {
|
} else {
|
||||||
// For (Windows) PowerShell, use sudo if available since it defaults to AllUsers scope
|
// For (Windows) PowerShell, use sudo since it defaults to AllUsers scope
|
||||||
// and may need administrator privileges
|
// and may need administrator privileges
|
||||||
powershell.build_command(ctx, &cmd, true)?.status_checked()
|
powershell.build_command(ctx, &cmd, true)?.status_checked()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,9 @@ pub fn run_chocolatey(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
|
|
||||||
print_separator("Chocolatey");
|
print_separator("Chocolatey");
|
||||||
|
|
||||||
let mut command = match ctx.sudo() {
|
let sudo = ctx.require_sudo()?;
|
||||||
Some(sudo) => sudo.execute(ctx, &choco)?,
|
|
||||||
None => ctx.execute(choco),
|
|
||||||
};
|
|
||||||
|
|
||||||
|
let mut command = sudo.execute(ctx, &choco)?;
|
||||||
command.args(["upgrade", "all"]);
|
command.args(["upgrade", "all"]);
|
||||||
|
|
||||||
if yes {
|
if yes {
|
||||||
@@ -42,10 +40,8 @@ pub fn run_winget(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
ctx.execute(&winget).args(["source", "update"]).status_checked()?;
|
ctx.execute(&winget).args(["source", "update"]).status_checked()?;
|
||||||
|
|
||||||
let mut command = if ctx.config().winget_use_sudo() {
|
let mut command = if ctx.config().winget_use_sudo() {
|
||||||
match ctx.sudo() {
|
let sudo = ctx.require_sudo()?;
|
||||||
Some(sudo) => sudo.execute(ctx, &winget)?,
|
sudo.execute(ctx, &winget)?
|
||||||
None => ctx.execute(winget),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ctx.execute(winget)
|
ctx.execute(winget)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -82,10 +82,11 @@ impl Powershell {
|
|||||||
cmd: &str,
|
cmd: &str,
|
||||||
use_sudo: bool,
|
use_sudo: bool,
|
||||||
) -> Result<impl CommandExt + 'a> {
|
) -> Result<impl CommandExt + 'a> {
|
||||||
// if use_sudo and sudo is available, use it, otherwise run directly
|
let mut command = if use_sudo {
|
||||||
let mut command = match ctx.sudo() {
|
let sudo = ctx.require_sudo()?;
|
||||||
Some(sudo) if use_sudo => sudo.execute(ctx, &self.path)?,
|
sudo.execute(ctx, &self.path)?
|
||||||
_ => ctx.execute(&self.path),
|
} else {
|
||||||
|
ctx.execute(&self.path)
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
|||||||
Reference in New Issue
Block a user