Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plugins versions being alpha compared #2947

Merged
merged 1 commit into from
Dec 4, 2024
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
5 changes: 4 additions & 1 deletion crates/plugins/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use reqwest::{header::HeaderMap, Client};
use serde::Serialize;
use spin_common::sha256;
use std::{
cmp::Ordering,
fs::{self, File},
io::{copy, Cursor},
path::{Path, PathBuf},
Expand Down Expand Up @@ -173,7 +174,9 @@ impl PluginManager {
name: plugin_manifest.name(),
version: installed.version,
});
} else if installed.version > plugin_manifest.version && !allow_downgrades {
} else if installed.compare_versions(plugin_manifest) == Some(Ordering::Greater)
&& !allow_downgrades
{
bail!(
"Newer version {} of plugin '{}' is already installed. To downgrade to version {}, run `spin plugins upgrade` with the `--downgrade` flag.",
installed.version,
Expand Down
10 changes: 10 additions & 0 deletions crates/plugins/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ impl PluginManifest {
pub fn try_version(&self) -> Result<semver::Version, semver::Error> {
semver::Version::parse(&self.version)
}

// Compares the versions. Returns None if either's version string is invalid semver.
pub fn compare_versions(&self, other: &Self) -> Option<std::cmp::Ordering> {
if let Ok(this_version) = self.try_version() {
if let Ok(other_version) = other.try_version() {
return Some(this_version.cmp_precedence(&other_version));
}
}
None
}
}

/// Describes compatibility and location of a plugin source.
Expand Down
Loading