diff --git a/src/main.rs b/src/main.rs index 8392acb9..fc10f166 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,7 @@ fn run() -> Result<(), Error> { let mut builder = formatted_timed_builder(); if config.verbose() { - builder.filter(Some("topgrade"), LevelFilter::Debug); + builder.filter(Some("topgrade"), LevelFilter::Trace); } builder.init(); diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index 4e5f4ee6..60099503 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -4,8 +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 serde::Deserialize; -use std::path::PathBuf; +use std::io; +use std::path::{Path, PathBuf}; +use std::process::{Command, Output}; use walkdir::WalkDir; static OS_RELEASE_PATH: &str = "/etc/os-release"; @@ -29,6 +32,16 @@ pub enum Distribution { Solus, } +/// Returns whether the given Python path is the system Python in Arch Linux +fn arch_system_python(path: &Path) -> Result { + 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 { let section = os_release.general_section(); @@ -111,7 +124,12 @@ fn upgrade_arch_linux(sudo: &Option, cleanup: bool, run_type: RunType) if let Some(yay) = which("yay") { if let Some(python) = which("python") { - if python != PathBuf::from("/usr/bin/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",