Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions src/backend/aqua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::file::TarOptions;
use crate::http::HTTP;
use crate::install_context::InstallContext;
use crate::lockfile::PlatformInfo;
use crate::path::{Path, PathBuf};
use crate::path::{Path, PathBuf, PathExt};
use crate::plugins::VERSION_REGEX;
use crate::registry::REGISTRY;
use crate::toolset::ToolVersion;
Expand Down Expand Up @@ -472,19 +472,38 @@ impl Backend for AquaBackend {
}

let install_path = tv.install_path();
let pkg = AQUA_REGISTRY
.package_with_version(&self.id, &[&tv.version])
.await?;
let cache: CacheManager<Vec<PathBuf>> =
CacheManagerBuilder::new(tv.cache_path().join("bin_paths.msgpack.z"))
.with_fresh_file(install_path.clone())
.with_fresh_duration(Settings::get().fetch_remote_versions_cache())
.build();

let srcs = self.srcs(&pkg, tv)?;
let paths: Vec<PathBuf> = if srcs.is_empty() {
vec![install_path.clone()]
} else {
srcs.iter()
.map(|(_, dst)| dst.parent().unwrap().to_path_buf())
.collect()
};
Ok(paths.into_iter().unique().filter(|p| p.exists()).collect())
let paths = cache
.get_or_try_init_async(async || {
let pkg = AQUA_REGISTRY
.package_with_version(&self.id, &[&tv.version])
.await?;

let srcs = self.srcs(&pkg, tv)?;
let paths = if srcs.is_empty() {
vec![install_path.clone()]
} else {
srcs.iter()
.map(|(_, dst)| dst.parent().unwrap().to_path_buf())
.collect()
};
Ok(paths
.into_iter()
.unique()
.filter(|p| p.exists())
.map(|p| p.strip_prefix(&install_path).unwrap().to_path_buf())
.collect())
})
.await?
.iter()
.map(|p| p.mount(&install_path))
.collect();
Ok(paths)
}

fn fuzzy_match_filter(&self, versions: Vec<String>, query: &str) -> Vec<String> {
Expand Down
14 changes: 14 additions & 0 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::dirs;
pub trait PathExt {
/// replaces $HOME with "~"
fn display_user(&self) -> String;
fn mount(&self, on: &Path) -> PathBuf;
fn is_empty(&self) -> bool;
}

impl PathExt for Path {
Expand All @@ -16,4 +18,16 @@ impl PathExt for Path {
false => self.to_string_lossy().to_string(),
}
}

fn mount(&self, on: &Path) -> PathBuf {
if PathExt::is_empty(self) {
on.to_path_buf()
} else {
on.join(self)
}
}

fn is_empty(&self) -> bool {
self.as_os_str().is_empty()
}
}
Loading