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};
12
12
use serde:: Serialize ;
13
13
use spin_common:: sha256;
14
14
use std:: {
15
+ cmp:: Ordering ,
15
16
fs:: { self , File } ,
16
17
io:: { copy, Cursor } ,
17
18
path:: { Path , PathBuf } ,
@@ -173,7 +174,9 @@ impl PluginManager {
173
174
name : plugin_manifest. name ( ) ,
174
175
version : installed. version ,
175
176
} ) ;
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
+ {
177
180
bail ! (
178
181
"Newer version {} of plugin '{}' is already installed. To downgrade to version {}, run `spin plugins upgrade` with the `--downgrade` flag." ,
179
182
installed. version,
Original file line number Diff line number Diff line change @@ -70,6 +70,16 @@ impl PluginManifest {
70
70
pub fn try_version ( & self ) -> Result < semver:: Version , semver:: Error > {
71
71
semver:: Version :: parse ( & self . version )
72
72
}
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
+ }
73
83
}
74
84
75
85
/// Describes compatibility and location of a plugin source.
You can’t perform that action at this time.
0 commit comments