@@ -42,6 +42,7 @@ import (
42
42
"github.com/lima-vm/lima/v2/pkg/sshutil"
43
43
"github.com/lima-vm/lima/v2/pkg/store"
44
44
"github.com/lima-vm/lima/v2/pkg/store/filenames"
45
+ "github.com/lima-vm/lima/v2/pkg/version/versionutil"
45
46
)
46
47
47
48
type HostAgent struct {
@@ -110,8 +111,16 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
110
111
return nil , err
111
112
}
112
113
114
+ var limaVersion string
115
+ limaVersionFile := filepath .Join (inst .Dir , filenames .LimaVersion )
116
+ if b , err := os .ReadFile (limaVersionFile ); err == nil {
117
+ limaVersion = strings .TrimSpace (string (b ))
118
+ } else if ! errors .Is (err , os .ErrNotExist ) {
119
+ logrus .WithError (err ).Warnf ("Failed to read %q" , limaVersionFile )
120
+ }
121
+
113
122
// inst.Config is loaded with FillDefault() already, so no need to care about nil pointers.
114
- sshLocalPort , err := determineSSHLocalPort (* inst .Config .SSH .LocalPort , instName )
123
+ sshLocalPort , err := determineSSHLocalPort (* inst .Config .SSH .LocalPort , instName , limaVersion )
115
124
if err != nil {
116
125
return nil , err
117
126
}
@@ -237,14 +246,14 @@ func writeSSHConfigFile(sshPath, instName, instDir, instSSHAddress string, sshLo
237
246
return os .WriteFile (fileName , b .Bytes (), 0o600 )
238
247
}
239
248
240
- func determineSSHLocalPort (confLocalPort int , instName string ) (int , error ) {
249
+ func determineSSHLocalPort (confLocalPort int , instName , limaVersion string ) (int , error ) {
241
250
if confLocalPort > 0 {
242
251
return confLocalPort , nil
243
252
}
244
253
if confLocalPort < 0 {
245
254
return 0 , fmt .Errorf ("invalid ssh local port %d" , confLocalPort )
246
255
}
247
- if instName == "default" {
256
+ if versionutil . LessThan ( limaVersion , "2.0.0" ) && instName == "default" {
248
257
// use hard-coded value for "default" instance, for backward compatibility
249
258
return 60022 , nil
250
259
}
0 commit comments