From 301170f17eadec98bb1b5d1dc2e2a886c2ff3be8 Mon Sep 17 00:00:00 2001 From: Eric Githinji <51313777+egithinji@users.noreply.github.com> Date: Wed, 13 Aug 2025 10:15:53 +0300 Subject: [PATCH] Uninstall old mdbook-linkcheck while installing project tools. (#2846) Fixes #2773 . --- xtask/src/main.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 6a469b46..f46eabd9 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -22,6 +22,7 @@ use anyhow::{Ok, Result, anyhow}; use clap::{Parser, Subcommand}; use std::path::{Path, PathBuf}; +use std::process::Stdio; use std::{env, process::Command}; fn main() -> Result<()> { @@ -128,9 +129,35 @@ fn install_tools() -> Result<()> { } } + // Uninstall original linkcheck if currently installed (see issue no 2773) + uninstall_mdbook_linkcheck(); + Ok(()) } +fn uninstall_mdbook_linkcheck() { + println!("Uninstalling old mdbook-linkcheck if installed..."); + let output = Command::new(env!("CARGO")) + .arg("uninstall") + .arg("mdbook-linkcheck") + .output() + .expect("Failed to execute cargo uninstall mdbook-linkcheck"); + + if !output.status.success() { + if String::from_utf8_lossy(&output.stderr) + .into_owned() + .contains("did not match any packages") + { + println!("mdbook-linkcheck not installed. Continuing..."); + } else { + eprintln!( + "An error occurred during uninstallation of mdbook-linkcheck:\n{:#?}", + String::from_utf8_lossy(&output.stderr) + ); + } + } +} + fn run_web_tests(dir: Option) -> Result<()> { println!("Running web tests...");