File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ use reqwest::{header::HeaderMap, Client};
1212use serde:: Serialize ;
1313use spin_common:: sha256;
1414use std:: {
15+ cmp:: Ordering ,
1516 fs:: { self , File } ,
1617 io:: { copy, Cursor } ,
1718 path:: { Path , PathBuf } ,
@@ -173,7 +174,9 @@ impl PluginManager {
173174 name : plugin_manifest. name ( ) ,
174175 version : installed. version ,
175176 } ) ;
176- } else if installed. version > plugin_manifest. version && !allow_downgrades {
177+ } else if installed. compare_versions ( plugin_manifest) == Some ( Ordering :: Greater )
178+ && !allow_downgrades
179+ {
177180 bail ! (
178181 "Newer version {} of plugin '{}' is already installed. To downgrade to version {}, run `spin plugins upgrade` with the `--downgrade` flag." ,
179182 installed. version,
Original file line number Diff line number Diff line change @@ -70,6 +70,16 @@ impl PluginManifest {
7070 pub fn try_version ( & self ) -> Result < semver:: Version , semver:: Error > {
7171 semver:: Version :: parse ( & self . version )
7272 }
73+
74+ // Compares the versions. Returns None if either's version string is invalid semver.
75+ pub fn compare_versions ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
76+ if let Ok ( this_version) = self . try_version ( ) {
77+ if let Ok ( other_version) = other. try_version ( ) {
78+ return Some ( this_version. cmp_precedence ( & other_version) ) ;
79+ }
80+ }
81+ None
82+ }
7383}
7484
7585/// Describes compatibility and location of a plugin source.
You can’t perform that action at this time.
0 commit comments