From 8ca5de7c34e3eb54750312fabcb901430bcf7f0d Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Mon, 9 Dec 2024 12:10:55 +0100 Subject: [PATCH] Allow self-update to fail when disabled --- src/steps/generic.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 1d125583..0cbeddd9 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -258,10 +258,24 @@ pub fn run_elan(ctx: &ExecutionContext) -> Result<()> { let elan = require("elan")?; print_separator("elan"); - ctx.run_type() - .execute(&elan) - .args(["self", "update"]) - .status_checked()?; + + let disabled = "self-update is disabled"; + let mut exec = ctx.run_type().execute(&elan); + let mut success = true; + if let Err(e) = exec.arg("self").arg("update").status_checked() { + error!("Self-update failed: {e}"); + if let Err(e) = exec.output_checked_utf8() { + success = match e.downcast_ref::() { + Some(TopgradeError::ProcessFailedWithOutput(_, _, stderr)) => stderr.contains(disabled), + _ => false + } + } + } + + if !success { + return Err(eyre!(StepFailed)) + } + ctx.run_type().execute(&elan).arg("update").status_checked() }