From fa95784ca7a47dbd30ef9e29c0ee40535060b508 Mon Sep 17 00:00:00 2001 From: matdexir Date: Sat, 13 Jul 2024 20:09:19 +0800 Subject: [PATCH] Fix: rm/uninstall not working when 'v' is missing for neovim versions. --- src/handlers/uninstall_handler.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/handlers/uninstall_handler.rs b/src/handlers/uninstall_handler.rs index 3661b2a..95c0af3 100644 --- a/src/handlers/uninstall_handler.rs +++ b/src/handlers/uninstall_handler.rs @@ -1,18 +1,18 @@ +use crate::{ + config::Config, + helpers::{self, directories}, +}; use anyhow::{anyhow, Result}; use dialoguer::{ console::{style, Term}, theme::ColorfulTheme, Confirm, MultiSelect, }; +use regex::Regex; use reqwest::Client; use tokio::fs; use tracing::{info, warn}; -use crate::{ - config::Config, - helpers::{self, directories}, -}; - /// Starts the uninstall process. /// /// This function creates a new HTTP client, determines the version to uninstall, checks if the version is currently in use, and if not, removes the version's directory. @@ -60,7 +60,13 @@ pub async fn start(version: Option<&str>, config: Config) -> Result<()> { Err(error) => return Err(anyhow!(error)), }; - let path = downloads_dir.join(&version.non_parsed_string); + let version_regex = Regex::new(r"^[0-9]+\.[0-9]+\.[0-9]+$")?; + let path = if version_regex.is_match(&version.non_parsed_string) { + let intermediate = format!("v{}", &version.non_parsed_string); + downloads_dir.join(intermediate) + } else { + downloads_dir.join(&version.non_parsed_string) + }; fs::remove_dir_all(path).await?; info!(