fix(powershell): execution policy check breaks when run in pwsh
When topgrade is run from within pwsh, the execution policy check breaks for the Windows Update and Windows Store steps, because they use normal powershell and the inherited PSModulePath environment variable breaks the Microsoft.PowerShell.Security module import. So we unset that variable to fix the issue, but also allow for those steps to use pwsh as neither step actually requires PowerShell 5. Co-authored-by: nistee <52573120+niStee@users.noreply.github.com>
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
#![allow(dead_code)]
|
||||
use color_eyre::eyre::Result;
|
||||
use std::env::var;
|
||||
use std::path::Path;
|
||||
use std::sync::{LazyLock, Mutex};
|
||||
|
||||
use crate::executor::RunType;
|
||||
use crate::powershell::Powershell;
|
||||
#[cfg(target_os = "linux")]
|
||||
use crate::steps::linux::Distribution;
|
||||
use crate::sudo::Sudo;
|
||||
use crate::utils::{get_require_sudo_string, require_option};
|
||||
use crate::{config::Config, executor::Executor};
|
||||
use color_eyre::eyre::Result;
|
||||
use std::env::var;
|
||||
use std::path::Path;
|
||||
use std::sync::Mutex;
|
||||
|
||||
pub struct ExecutionContext<'a> {
|
||||
run_type: RunType,
|
||||
@@ -22,6 +24,7 @@ pub struct ExecutionContext<'a> {
|
||||
under_ssh: bool,
|
||||
#[cfg(target_os = "linux")]
|
||||
distribution: &'a Result<Distribution>,
|
||||
powershell: LazyLock<Powershell>,
|
||||
}
|
||||
|
||||
impl<'a> ExecutionContext<'a> {
|
||||
@@ -40,6 +43,7 @@ impl<'a> ExecutionContext<'a> {
|
||||
under_ssh,
|
||||
#[cfg(target_os = "linux")]
|
||||
distribution,
|
||||
powershell: LazyLock::new(Powershell::new),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,4 +80,8 @@ impl<'a> ExecutionContext<'a> {
|
||||
pub fn distribution(&self) -> &Result<Distribution> {
|
||||
self.distribution
|
||||
}
|
||||
|
||||
pub fn powershell(&self) -> &Powershell {
|
||||
&self.powershell
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user