From a6abb7c6bc09d1d30c18155c1a7593562187275e Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Mon, 25 Jun 2018 22:35:58 +0300 Subject: [PATCH] Rustup should update itself when appropriate (fixes #30) --- README.md | 1 + src/steps.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index d9692fde..d24b9185 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Just run `topgrade`. It will run the following steps: * Custom defined paths * *Unix*: Run [zplug](https://github.com/zplug/zplug) update * *Unix*: Upgrade tmux plugins with [TPM](https://github.com/tmux-plugins/tpm) +* Update Rustup by running `rustup update`. This will also attempt to run `rustup self update` when Rustup is installed inside the home directory. * Run Cargo [install-update](https://github.com/nabijaczleweli/cargo-update) * Upgrade Emacs packages * Upgrade Vim packages. Works with the following plugin frameworks: diff --git a/src/steps.rs b/src/steps.rs index 0d70dec3..c316ba37 100644 --- a/src/steps.rs +++ b/src/steps.rs @@ -1,7 +1,9 @@ use super::utils::Check; use failure; +use std::env::home_dir; use std::path::PathBuf; use std::process::Command; +use utils::is_ancestor; const EMACS_UPGRADE: &str = include_str!("emacs.el"); @@ -111,6 +113,14 @@ pub fn run_fwupdmgr(fwupdmgr: &PathBuf) -> Result<(), failure::Error> { } pub fn run_rustup(rustup: &PathBuf) -> Result<(), failure::Error> { + if is_ancestor(&home_dir().unwrap(), &rustup) { + Command::new(rustup) + .args(&["self", "update"]) + .spawn()? + .wait()? + .check()?; + } + Command::new(rustup).arg("update").spawn()?.wait()?.check()?; Ok(())