@@ -16,13 +16,13 @@ import (
16
16
"text/template"
17
17
"time"
18
18
19
- "github.com/coreos/go-semver/semver"
20
19
"github.com/docker/go-units"
21
20
hostagentclient "github.com/lima-vm/lima/pkg/hostagent/api/client"
22
21
"github.com/lima-vm/lima/pkg/limayaml"
23
22
"github.com/lima-vm/lima/pkg/store/dirnames"
24
23
"github.com/lima-vm/lima/pkg/store/filenames"
25
24
"github.com/lima-vm/lima/pkg/textutil"
25
+ "github.com/lima-vm/lima/pkg/version/versionutil"
26
26
"github.com/sirupsen/logrus"
27
27
)
28
28
@@ -174,7 +174,7 @@ func Inspect(instName string) (*Instance, error) {
174
174
limaVersionFile := filepath .Join (instDir , filenames .LimaVersion )
175
175
if version , err := os .ReadFile (limaVersionFile ); err == nil {
176
176
inst .LimaVersion = strings .TrimSpace (string (version ))
177
- if _ , err = parseLimaVersion (inst .LimaVersion ); err != nil {
177
+ if _ , err = versionutil . Parse (inst .LimaVersion ); err != nil {
178
178
logrus .Warnf ("treating lima version %q from %q as very latest release" , inst .LimaVersion , limaVersionFile )
179
179
}
180
180
} else if ! errors .Is (err , os .ErrNotExist ) {
@@ -436,36 +436,3 @@ func (inst *Instance) Unprotect() error {
436
436
inst .Protected = false
437
437
return nil
438
438
}
439
-
440
- // parseLimaVersion parses a Lima version string by removing the leading "v" character and
441
- // stripping everything from the first "-" forward (which are `git describe` artifacts and
442
- // not semver pre-release markers). So "v0.19.1-16-gf3dc6ed.m" will be parsed as "0.19.1".
443
- func parseLimaVersion (version string ) (* semver.Version , error ) {
444
- version = strings .TrimPrefix (version , "v" )
445
- version , _ , _ = strings .Cut (version , "-" )
446
- return semver .NewVersion (version )
447
- }
448
-
449
- // LimaVersionGreaterThan returns true if the Lima version used to create an instance is greater
450
- // than a specific older version. Always returns false if the Lima version is the empty string.
451
- // Unparsable lima versions (like SHA1 commit ids) are treated as the latest version and return true.
452
- // limaVersion is a `github describe` string, not a semantic version. So "0.19.1-16-gf3dc6ed.m"
453
- // will be considered greater than "0.19.1".
454
- func LimaVersionGreaterThan (limaVersion , oldVersion string ) bool {
455
- if limaVersion == "" {
456
- return false
457
- }
458
- version , err := parseLimaVersion (limaVersion )
459
- if err != nil {
460
- return true
461
- }
462
- switch version .Compare (* semver .New (oldVersion )) {
463
- case - 1 :
464
- return false
465
- case + 1 :
466
- return true
467
- case 0 :
468
- return strings .Contains (limaVersion , "-" )
469
- }
470
- panic ("unreachable" )
471
- }
0 commit comments