Skip to content

Commit

Permalink
Update linking.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Oct 25, 2024
1 parent 7087b20 commit 7a3a419
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 36 deletions.
1 change: 1 addition & 0 deletions crates/cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ pub async fn purge_tool(session: &ProtoSession, id: &Id, yes: bool) -> miette::R
fs::remove_dir_all(inventory_dir)?;

// Delete binaries
// TODO
for bin in tool.resolve_bin_locations().await? {
session.env.store.unlink_bin(&bin.path)?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async fn pin_version(
}

if pin {
internal_pin(tool, &spec, pin_type, true).await?;
internal_pin(tool, &spec, pin_type).await?;
}

Ok(pin)
Expand Down
9 changes: 1 addition & 8 deletions crates/cli/src/commands/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ pub async fn internal_pin(
tool: &mut Tool,
spec: &UnresolvedVersionSpec,
pin: PinType,
link: bool,
) -> miette::Result<PathBuf> {
// Create symlink to this new version
if pin == PinType::Global && link {
tool.symlink_bins(true).await?;
}

let config_path = ProtoConfig::update(tool.proto.get_config_dir(pin), |config| {
config
.versions
Expand Down Expand Up @@ -64,8 +58,7 @@ pub async fn pin(session: ProtoSession, args: PinArgs) -> AppResult {
args.spec.clone()
};

let config_path =
internal_pin(&mut tool, &spec, map_pin_type(args.global, args.to), false).await?;
let config_path = internal_pin(&mut tool, &spec, map_pin_type(args.global, args.to)).await?;

println!(
"Pinned {} to {} in {}",
Expand Down
19 changes: 9 additions & 10 deletions crates/cli/src/commands/regen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,26 @@ pub async fn regen(session: ProtoSession, args: RegenArgs) -> AppResult {
debug!("Loading tools");

let config = session.env.load_config()?;
let global_config = session.env.load_config_manager()?.get_global_config()?;

for mut tool in session.load_tools().await? {
// Shims
// Shims - Create once for the configured version.
if let Some(version) = config.versions.get(&tool.id) {
debug!("Regenerating {} shim", tool.get_name());

tool.resolve_version(version, true).await?;
tool.generate_shims(true).await?;
tool.generate_shims(false).await?;
}

// Bins
// Symlinks are only based on the globally pinned versions,
// so we must reference that config instead of the merged one!
// Bins - Create for each installed version.
if args.bin {
if let Some(version) = global_config.versions.get(&tool.id) {
debug!("Relinking {} bin", tool.get_name());
debug!("Relinking {} bin", tool.get_name());

for version in tool.inventory.manifest.installed_versions.clone() {
let version = version.to_unresolved_spec();

tool.version = None;
tool.resolve_version(version, true).await?;
tool.symlink_bins(true).await?;
tool.resolve_version(&version, true).await?;
tool.symlink_bins(false).await?;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions crates/core/src/flow/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ impl Tool {
}

let mut registry: ShimsMap = BTreeMap::default();
registry.insert(self.id.to_string(), Shim::default());

let mut to_create = vec![];

for shim in shims {
Expand Down
11 changes: 9 additions & 2 deletions crates/core/src/flow/locate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl Tool {
/// to the binaries final location.
pub async fn resolve_bin_locations(&self) -> miette::Result<Vec<ExecutableLocation>> {
let output = self.call_locate_executables().await?;
let version = self.get_resolved_version();
let mut locations = vec![];

let mut add = |name: String, config: ExecutableConfig| {
Expand All @@ -113,9 +114,15 @@ impl Tool {
.or(config.exe_path.as_ref())
.is_some()
{
let versioned_name = format!("{name}-{version}");

locations.push(ExecutableLocation {
path: self.proto.store.bin_dir.join(get_exe_file_name(&name)),
name,
path: self
.proto
.store
.bin_dir
.join(get_exe_file_name(&versioned_name)),
name: versioned_name,
config,
});
}
Expand Down
8 changes: 2 additions & 6 deletions crates/core/src/flow/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ impl Tool {
}

let version = self.get_resolved_version();
let mut removed_default_version = false;

// Remove version from manifest
let manifest = &mut self.inventory.manifest;
Expand All @@ -118,17 +117,14 @@ impl Tool {
debug!("Unpinning global version");

versions.remove(&self.id);
removed_default_version = true;
}
}
})?;

// If no more default version, delete the symlink,
// otherwise the OS will throw errors for missing sources
if removed_default_version || self.inventory.manifest.installed_versions.is_empty() {
for bin in self.resolve_bin_locations().await? {
self.proto.store.unlink_bin(&bin.path)?;
}
for bin in self.resolve_bin_locations().await? {
self.proto.store.unlink_bin(&bin.path)?;
}

// If no more versions in general, delete all shims
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/layout/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ impl fmt::Debug for Store {
f.debug_struct("Store")
.field("dir", &self.dir)
.field("bin_dir", &self.bin_dir)
.field("cache_dir", &self.cache_dir)
.field("inventory_dir", &self.inventory_dir)
.field("plugins_dir", &self.plugins_dir)
.field("shims_dir", &self.shims_dir)
Expand Down
10 changes: 3 additions & 7 deletions crates/warpgate/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ pub fn create_cache_key(url: &str, seed: Option<&str>) -> String {
}

pub fn determine_cache_extension(value: &str) -> Option<&str> {
for ext in [".toml", ".json", ".jsonc", ".yaml", ".yml", ".wasm", ".txt"] {
if value.ends_with(ext) {
return Some(ext);
}
}

None
[".toml", ".json", ".jsonc", ".yaml", ".yml", ".wasm", ".txt"]
.into_iter()
.find(|ext| value.ends_with(ext))
}

pub async fn download_from_url_to_file(
Expand Down

0 comments on commit 7a3a419

Please sign in to comment.