@@ -42,6 +42,7 @@ import (
4242 "github.com/lima-vm/lima/v2/pkg/sshutil"
4343 "github.com/lima-vm/lima/v2/pkg/store"
4444 "github.com/lima-vm/lima/v2/pkg/store/filenames"
45+ "github.com/lima-vm/lima/v2/pkg/version/versionutil"
4546)
4647
4748type HostAgent struct {
@@ -110,8 +111,16 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
110111 return nil , err
111112 }
112113
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+
113122 // 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 )
115124 if err != nil {
116125 return nil , err
117126 }
@@ -237,14 +246,14 @@ func writeSSHConfigFile(sshPath, instName, instDir, instSSHAddress string, sshLo
237246 return os .WriteFile (fileName , b .Bytes (), 0o600 )
238247}
239248
240- func determineSSHLocalPort (confLocalPort int , instName string ) (int , error ) {
249+ func determineSSHLocalPort (confLocalPort int , instName , limaVersion string ) (int , error ) {
241250 if confLocalPort > 0 {
242251 return confLocalPort , nil
243252 }
244253 if confLocalPort < 0 {
245254 return 0 , fmt .Errorf ("invalid ssh local port %d" , confLocalPort )
246255 }
247- if instName == "default" {
256+ if versionutil . LessThan ( limaVersion , "2.0.0" ) && instName == "default" {
248257 // use hard-coded value for "default" instance, for backward compatibility
249258 return 60022 , nil
250259 }
0 commit comments