Skip to content

Commit

Permalink
fix: incorrectly displaying "cargo-" as tool versions instead of "car…
Browse files Browse the repository at this point in the history
…go:"

Fixes #3025
  • Loading branch information
jdx committed Nov 14, 2024
1 parent 341a6f1 commit aeaea11
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
5 changes: 5 additions & 0 deletions e2e/cli/test_ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

mise i cargo:usage-cli
assert_contains "mise ls" "cargo:usage-cli"
assert_not_contains "mise ls" "cargo-usage-cli" # if the backend meta file isn't working right these will be displayed
2 changes: 1 addition & 1 deletion src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ pub trait Backend: Debug + Send + Sync {
fn write_backend_meta(&self) -> eyre::Result<()> {
file::write(
self.ba().installs_path.join(".mise.backend"),
self.ba().full(),
format!("{}\n{}", self.ba().short, self.ba().full()),
)
}
}
Expand Down
40 changes: 30 additions & 10 deletions src/toolset/install_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type InstallStateTools = BTreeMap<String, InstallStateTool>;
#[derive(Debug, Clone)]
pub struct InstallStateTool {
pub short: String,
pub _dir: PathBuf,
pub full: String,
pub backend_type: BackendType,
pub versions: Vec<String>,
Expand Down Expand Up @@ -67,6 +68,7 @@ fn init_tools() -> Result<MutexGuard<'static, Option<BTreeMap<String, InstallSta
.map(|(short, pt)| {
let tool = InstallStateTool {
short: short.clone(),
_dir: dirs::PLUGINS.join(short),
backend_type: match pt {
PluginType::Asdf => BackendType::Asdf,
PluginType::Vfox => BackendType::Vfox,
Expand All @@ -83,9 +85,16 @@ fn init_tools() -> Result<MutexGuard<'static, Option<BTreeMap<String, InstallSta
let dirs = file::dir_subdirs(&dirs::INSTALLS)?;
tools.extend(
dirs.into_iter()
.map(|short| {
let dir = dirs::INSTALLS.join(&short);
let full = if let Some(full) = short_to_full(&short)? {
.map(|dir| {
let mut short = dir.clone();
let mut full = None;
let backend_meta = read_backend_meta(&dir).unwrap_or_default();
if backend_meta.len() == 2 {
short = backend_meta[0].clone();
full = Some(backend_meta[1].clone());
}
let dir = dirs::INSTALLS.join(&dir);
let full = if let Some(full) = short_to_full(&short, full)? {
full
} else {
return Ok(None);
Expand All @@ -104,6 +113,7 @@ fn init_tools() -> Result<MutexGuard<'static, Option<BTreeMap<String, InstallSta
.collect();
let tool = InstallStateTool {
short: short.clone(),
_dir: dir.clone(),
full,
backend_type,
versions,
Expand All @@ -119,15 +129,15 @@ fn init_tools() -> Result<MutexGuard<'static, Option<BTreeMap<String, InstallSta
Ok(mu)
}

pub fn short_to_full(short: &str) -> Result<Option<String>> {
pub fn short_to_full(short: &str, meta_full: Option<String>) -> Result<Option<String>> {
let plugins = init_plugins()?;
let plugins = plugins.as_ref().unwrap();
if let Some(plugin) = plugins.get(short) {
match plugin {
PluginType::Asdf => Ok(Some(format!("asdf:{short}"))),
PluginType::Vfox => Ok(Some(format!("vfox:{short}"))),
}
} else if let Some(full) = read_backend_meta(short) {
} else if let Some(full) = meta_full {
Ok(Some(full))
} else if let Some(full) = REGISTRY
.get(short)
Expand Down Expand Up @@ -183,12 +193,17 @@ fn backend_meta_path(short: &str) -> PathBuf {
dirs::INSTALLS.join(short).join(".mise.backend")
}

fn migrate_backend_meta_json(short: &str) {
let old = dirs::INSTALLS.join(short).join(".mise.backend.json");
fn migrate_backend_meta_json(dir: &str) {
let old = dirs::INSTALLS.join(dir).join(".mise.backend.json");
let migrate = || {
let json: serde_json::Value = serde_json::from_reader(file::open(&old)?)?;
if let Some(full) = json.get("id").and_then(|id| id.as_str()) {
file::write(backend_meta_path(short), full.trim())?;
let short = json
.get("short")
.and_then(|short| short.as_str())
.unwrap_or(dir);
let doc = format!("{}\n{}", short, full);
file::write(backend_meta_path(dir), doc.trim())?;
}
Ok(())
};
Expand All @@ -202,7 +217,7 @@ fn migrate_backend_meta_json(short: &str) {
}
}

fn read_backend_meta(short: &str) -> Option<String> {
fn read_backend_meta(short: &str) -> Option<Vec<String>> {
migrate_backend_meta_json(short);
let path = backend_meta_path(short);
if path.exists() {
Expand All @@ -211,7 +226,12 @@ fn read_backend_meta(short: &str) -> Option<String> {
warn!("{err:?}");
})
.unwrap_or_default();
Some(body)
Some(
body.lines()
.filter(|f| !f.is_empty())
.map(|f| f.to_string())
.collect(),
)
} else {
None
}
Expand Down

0 comments on commit aeaea11

Please sign in to comment.