Set PATH when running yay (fix #192)
Instead of causing an error when the Python in path is not the system Python, we prepend /usr/bin to PATH and then run yay.
This commit is contained in:
@@ -31,10 +31,6 @@ pub enum ErrorKind {
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
UnknownLinuxDistribution,
|
UnknownLinuxDistribution,
|
||||||
|
|
||||||
#[fail(display = "Detected Python is not the system Python")]
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
NotSystemPython,
|
|
||||||
|
|
||||||
#[fail(display = "Process execution failure")]
|
#[fail(display = "Process execution failure")]
|
||||||
ProcessExecution,
|
ProcessExecution,
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,23 @@ impl Executor {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
/// See `std::process::Command::env`
|
||||||
|
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Executor
|
||||||
|
where
|
||||||
|
K: AsRef<OsStr>,
|
||||||
|
V: AsRef<OsStr>,
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Executor::Wet(c) => {
|
||||||
|
c.env(key, val);
|
||||||
|
}
|
||||||
|
Executor::Dry(_) => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// See `std::process::Command::spawn`
|
/// See `std::process::Command::spawn`
|
||||||
pub fn spawn(&mut self) -> Result<ExecutorChild, Error> {
|
pub fn spawn(&mut self) -> Result<ExecutorChild, Error> {
|
||||||
let result = match self {
|
let result = match self {
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ use crate::terminal::{print_separator, print_warning};
|
|||||||
use crate::utils::{require, require_option, which};
|
use crate::utils::{require, require_option, which};
|
||||||
use failure::ResultExt;
|
use failure::ResultExt;
|
||||||
use ini::Ini;
|
use ini::Ini;
|
||||||
use log::{debug, error};
|
use log::debug;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::io;
|
use std::env::var_os;
|
||||||
use std::path::{Path, PathBuf};
|
use std::ffi::OsString;
|
||||||
use std::process::{Command, Output};
|
use std::path::PathBuf;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
static OS_RELEASE_PATH: &str = "/etc/os-release";
|
static OS_RELEASE_PATH: &str = "/etc/os-release";
|
||||||
@@ -32,16 +32,6 @@ pub enum Distribution {
|
|||||||
Solus,
|
Solus,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the given Python path is the system Python in Arch Linux
|
|
||||||
fn arch_system_python(path: &Path) -> Result<bool, io::Error> {
|
|
||||||
debug!("Python is in {}", path.display());
|
|
||||||
Command::new("pacman").arg("-Qqo").arg(&path).output().map(|output| {
|
|
||||||
debug!("Pacman output: {:?}", output);
|
|
||||||
let Output { status, stdout, .. } = output;
|
|
||||||
status.success() && String::from_utf8(stdout).unwrap() == "python\n"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Distribution {
|
impl Distribution {
|
||||||
fn parse_os_release(os_release: &ini::Ini) -> Result<Self, Error> {
|
fn parse_os_release(os_release: &ini::Ini) -> Result<Self, Error> {
|
||||||
let section = os_release.general_section();
|
let section = os_release.general_section();
|
||||||
@@ -119,30 +109,28 @@ pub fn show_pacnew() {
|
|||||||
fn upgrade_arch_linux(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
fn upgrade_arch_linux(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
||||||
let pacman = which("powerpill").unwrap_or_else(|| PathBuf::from("/usr/bin/pacman"));
|
let pacman = which("powerpill").unwrap_or_else(|| PathBuf::from("/usr/bin/pacman"));
|
||||||
|
|
||||||
if let Some(yay) = which("yay") {
|
let path = {
|
||||||
if let Some(python) = which("python") {
|
let mut path = OsString::from("/usr/bin:");
|
||||||
let is_system_python = arch_system_python(&python).unwrap_or_else(|e| {
|
path.push(var_os("PATH").unwrap());
|
||||||
error!("Error detecting system Python: {}", e);
|
path
|
||||||
false
|
};
|
||||||
});
|
debug!("Running Arch update with path: {:?}", path);
|
||||||
|
|
||||||
if !is_system_python {
|
if let Some(yay) = which("yay") {
|
||||||
print_warning(format!(
|
|
||||||
"Python detected at {:?}, which is probably not the system Python.
|
|
||||||
It's dangerous to run yay since Python based AUR packages will be installed in the wrong location",
|
|
||||||
python
|
|
||||||
));
|
|
||||||
return Err(ErrorKind::NotSystemPython)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
run_type
|
run_type
|
||||||
.execute(yay)
|
.execute(yay)
|
||||||
.arg("--pacman")
|
.arg("--pacman")
|
||||||
.arg(pacman)
|
.arg(pacman)
|
||||||
.arg("-Syu")
|
.arg("-Syu")
|
||||||
|
.env("PATH", path)
|
||||||
.check_run()?;
|
.check_run()?;
|
||||||
} else if let Some(sudo) = &sudo {
|
} else if let Some(sudo) = &sudo {
|
||||||
run_type.execute(&sudo).arg(pacman).arg("-Syu").check_run()?;
|
run_type
|
||||||
|
.execute(&sudo)
|
||||||
|
.arg(pacman)
|
||||||
|
.arg("-Syu")
|
||||||
|
.env("PATH", path)
|
||||||
|
.check_run()?;
|
||||||
} else {
|
} else {
|
||||||
print_warning("No sudo or yay detected. Skipping system upgrade");
|
print_warning("No sudo or yay detected. Skipping system upgrade");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user