Skip to content

Commit

Permalink
Detect Elan self update disabled (e.g. installed from distro repos) (#…
Browse files Browse the repository at this point in the history
…998)

* Add config option for Elan self-update

* Format & Config

* Revert "Format & Config"

This reverts commit 9eedecc.

* Revert "Add config option for Elan self-update"

This reverts commit 8c80c7a.

* Allow self-update to fail when disabled

* Formatting

* Don't print in case of failed self-update

* Formatting

* Use the code suggested :)

* Follow the recommendations by Clippy
  • Loading branch information
grahnen authored Dec 12, 2024
1 parent dc9d8d5 commit c5f2d7b
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/steps/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,35 @@ 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_error_msg = "self-update is disabled";
let executor_output = ctx.run_type().execute(&elan).args(["self", "update"]).output()?;
match executor_output {
ExecutorOutput::Wet(command_output) => {
if command_output.status.success() {
// Flush the captured output
std::io::stdout().lock().write_all(&command_output.stdout).unwrap();
std::io::stderr().lock().write_all(&command_output.stderr).unwrap();
} else {
let stderr_as_str = std::str::from_utf8(&command_output.stderr).unwrap();
if stderr_as_str.contains(disabled_error_msg) {
// `elan` is externally managed, we cannot do the update. Users
// won't see any error message because Topgrade captures them
// all.
} else {
// `elan` is NOT externally managed, `elan self update` can
// be performed, but the invocation failed, so we report the
// error to the user and error out.
std::io::stdout().lock().write_all(&command_output.stdout).unwrap();
std::io::stderr().lock().write_all(&command_output.stderr).unwrap();

return Err(StepFailed.into());
}
}
}
ExecutorOutput::Dry => { /* nothing needed because in a dry run */ }
}

ctx.run_type().execute(&elan).arg("update").status_checked()
}

Expand Down

0 comments on commit c5f2d7b

Please sign in to comment.