From 544d87d3ef3aa7794ed89bed6ecf6a3371ec8003 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Tue, 12 Jun 2018 21:35:04 +0300 Subject: [PATCH] Do not run yay if Python is not the system Python (fixes #13) --- src/linux.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/linux.rs b/src/linux.rs index 7a3ac8fa..ed147368 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -19,6 +19,10 @@ pub enum Distribution { #[fail(display = "Unknown Linux Distribution")] struct UnknownLinuxDistribution; +#[derive(Debug, Fail)] +#[fail(display = "Detected Python is not the system Python")] +struct NotSystemPython; + impl Distribution { pub fn detect() -> Result { let content = fs::read_to_string("/etc/os-release")?; @@ -52,6 +56,17 @@ pub fn upgrade_arch_linux( terminal: &Terminal, ) -> Result<(), failure::Error> { if let Ok(yay) = which("yay") { + if let Ok(python) = which("python") { + if python != PathBuf::from("/usr/bin/python") { + terminal.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(NotSystemPython.into()); + } + } + Command::new(yay).spawn()?.wait()?.check()?; } else { if let Some(sudo) = &sudo {