diff --git a/CHANGELOG.md b/CHANGELOG.md index d67b6017f..6efabd672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,15 @@ #### 🚀 Updates - Added a `proto migrate v0.24` command for migrating aliases/versions. We'll also log a warning if we detect the old configuration. +- Updated non-latest plugins to be cached for 30 days, instead of forever. + +#### 🐞 Fixes + +- Fixed an issue where resolving canary versions wouldn't work correctly. + +#### ⚙️ Internal + +- We now load and cache the user config, instead of continually loading it. ## 0.23.2 diff --git a/crates/cli/src/commands/migrate/v0_24.rs b/crates/cli/src/commands/migrate/v0_24.rs index 5ff1d3a03..188d69703 100644 --- a/crates/cli/src/commands/migrate/v0_24.rs +++ b/crates/cli/src/commands/migrate/v0_24.rs @@ -30,8 +30,8 @@ pub async fn migrate() -> SystemResult { updated_manifest = true; } - if !tool.manifest.default_version.is_some() { - debug!("Found a default version"); + if tool.manifest.default_version.is_some() { + debug!("Found default version"); let entry = user_config.tools.entry(tool.id.clone()).or_default(); entry.default_version = manifest.default_version.take(); diff --git a/crates/cli/src/commands/run.rs b/crates/cli/src/commands/run.rs index a139263ad..5777ffc7a 100644 --- a/crates/cli/src/commands/run.rs +++ b/crates/cli/src/commands/run.rs @@ -154,9 +154,7 @@ pub async fn run(args: ArgsRef) -> SystemResult { // Check if installed or install if !tool.is_setup(&version).await? { - let user_config = tool.proto.load_user_config()?; - - if !user_config.auto_install { + if !tool.proto.load_user_config()?.auto_install { return Err(ProtoError::MissingToolForRun { tool: tool.get_name().to_owned(), version: version.to_string(), diff --git a/crates/cli/src/commands/tool/list.rs b/crates/cli/src/commands/tool/list.rs index 04f82d0ee..2e4d67814 100644 --- a/crates/cli/src/commands/tool/list.rs +++ b/crates/cli/src/commands/tool/list.rs @@ -53,13 +53,13 @@ pub async fn list(args: ArgsRef) { .map(|t| { let user_config = user_config.tools.remove(&t.id); - return ( + ( t.id, ToolItem { manifest: t.manifest, user_config, }, - ); + ) }) .collect::>(); diff --git a/crates/core/tests/version_resolver_test.rs b/crates/core/tests/version_resolver_test.rs index 53445ac39..42fdb4a84 100644 --- a/crates/core/tests/version_resolver_test.rs +++ b/crates/core/tests/version_resolver_test.rs @@ -1,4 +1,6 @@ -use proto_core::{resolve_version, ToolManifest, UnresolvedVersionSpec, VersionSpec}; +use proto_core::{ + resolve_version, ToolManifest, UnresolvedVersionSpec, UserToolConfig, VersionSpec, +}; use semver::Version; use std::collections::BTreeMap; @@ -43,15 +45,6 @@ mod version_resolver { fn create_manifest() -> ToolManifest { let mut manifest = ToolManifest::default(); - manifest.aliases.insert( - "latest-manifest".into(), - UnresolvedVersionSpec::Version(Version::new(8, 0, 0)), - ); - manifest.aliases.insert( - "stable-manifest".into(), - UnresolvedVersionSpec::Alias("stable".into()), - ); - manifest .installed_versions .insert(VersionSpec::parse("3.0.0").unwrap()); @@ -62,6 +55,21 @@ mod version_resolver { manifest } + fn create_tool_config() -> UserToolConfig { + let mut config = UserToolConfig::default(); + + config.aliases.insert( + "latest-manifest".into(), + UnresolvedVersionSpec::Version(Version::new(8, 0, 0)), + ); + config.aliases.insert( + "stable-manifest".into(), + UnresolvedVersionSpec::Alias("stable".into()), + ); + + config + } + #[test] fn resolves_aliases() { let versions = create_versions(); @@ -93,10 +101,11 @@ mod version_resolver { } #[test] - fn resolves_aliases_from_manifest() { + fn resolves_aliases_from_config() { let versions = create_versions(); let aliases = create_aliases(); let manifest = create_manifest(); + let config = create_tool_config(); assert_eq!( resolve_version( @@ -104,7 +113,7 @@ mod version_resolver { &versions, &aliases, Some(&manifest), - None, + Some(&config), ) .unwrap(), Version::new(8, 0, 0) @@ -116,7 +125,7 @@ mod version_resolver { &versions, &aliases, Some(&manifest), - None, + Some(&config), ) .unwrap(), Version::new(10, 0, 0) @@ -202,10 +211,11 @@ mod version_resolver { } #[test] - fn resolves_versions_from_manifest() { + fn resolves_versions_from_config() { let versions = create_versions(); let aliases = create_aliases(); let manifest = create_manifest(); + let config = create_tool_config(); assert_eq!( resolve_version( @@ -213,7 +223,7 @@ mod version_resolver { &versions, &aliases, Some(&manifest), - None, + Some(&config), ) .unwrap(), Version::new(3, 0, 0) @@ -263,10 +273,11 @@ mod version_resolver { } #[test] - fn resolves_partial_versions_with_manifest() { + fn resolves_partial_versions_with_config() { let versions = create_versions(); let aliases = create_aliases(); let manifest = create_manifest(); + let config = create_tool_config(); assert_eq!( resolve_version( @@ -274,7 +285,7 @@ mod version_resolver { &versions, &aliases, Some(&manifest), - None, + Some(&config), ) .unwrap(), Version::new(3, 3, 3) @@ -286,7 +297,7 @@ mod version_resolver { &versions, &aliases, Some(&manifest), - None, + Some(&config), ) .unwrap(), Version::new(3, 3, 3) diff --git a/crates/warpgate/src/loader.rs b/crates/warpgate/src/loader.rs index 0204e4c09..d1b70e596 100644 --- a/crates/warpgate/src/loader.rs +++ b/crates/warpgate/src/loader.rs @@ -140,25 +140,26 @@ impl PluginLoader { return Ok(false); } - let mut cached = true; + let metadata = fs::metadata(path)?; - // If latest, cache only lasts for 7 days - if fs::file_name(path).contains("-latest-") { - let metadata = fs::metadata(path)?; - - cached = if let Ok(filetime) = metadata.created().or_else(|_| metadata.modified()) { - filetime > SystemTime::now() - Duration::from_secs(86400 * 7) + let mut cached = if let Ok(filetime) = metadata.created().or_else(|_| metadata.modified()) { + let days = if fs::file_name(path).contains("-latest-") { + 7 } else { - false + 30 }; - if !cached && self.is_offline() { - cached = true; - } + filetime > SystemTime::now() - Duration::from_secs(86400 * days) + } else { + false + }; - if !cached { - fs::remove_file(path)?; - } + if !cached && self.is_offline() { + cached = true; + } + + if !cached { + fs::remove_file(path)?; } if cached {