Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Set PATH when running yay (fix #192)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
r-darwish committed Aug 15, 2019
1 parent d552360 commit 69dfcfe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
4 changes: 0 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ pub enum ErrorKind {
#[cfg(target_os = "linux")]
UnknownLinuxDistribution,

#[fail(display = "Detected Python is not the system Python")]
#[cfg(target_os = "linux")]
NotSystemPython,

#[fail(display = "Process execution failure")]
ProcessExecution,

Expand Down
17 changes: 17 additions & 0 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ impl Executor {
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`
pub fn spawn(&mut self) -> Result<ExecutorChild, Error> {
let result = match self {
Expand Down
48 changes: 18 additions & 30 deletions src/steps/os/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use crate::terminal::{print_separator, print_warning};
use crate::utils::{require, require_option, which};
use failure::ResultExt;
use ini::Ini;
use log::{debug, error};
use log::debug;
use serde::Deserialize;
use std::io;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use std::env::var_os;
use std::ffi::OsString;
use std::path::PathBuf;
use walkdir::WalkDir;

static OS_RELEASE_PATH: &str = "/etc/os-release";
Expand All @@ -32,16 +32,6 @@ pub enum Distribution {
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 {
fn parse_os_release(os_release: &ini::Ini) -> Result<Self, Error> {
let section = os_release.general_section();
Expand Down Expand Up @@ -119,30 +109,28 @@ pub fn show_pacnew() {
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 path = {
let mut path = OsString::from("/usr/bin:");
path.push(var_os("PATH").unwrap());
path
};
debug!("Running Arch update with path: {:?}", path);

if let Some(yay) = which("yay") {
if let Some(python) = which("python") {
let is_system_python = arch_system_python(&python).unwrap_or_else(|e| {
error!("Error detecting system Python: {}", e);
false
});

if !is_system_python {
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
.execute(yay)
.arg("--pacman")
.arg(pacman)
.arg("-Syu")
.env("PATH", path)
.check_run()?;
} 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 {
print_warning("No sudo or yay detected. Skipping system upgrade");
}
Expand Down

0 comments on commit 69dfcfe

Please sign in to comment.