7
7
"os/exec"
8
8
"strings"
9
9
10
+ "github.com/coreos/go-semver/semver"
10
11
"github.com/lima-vm/lima/pkg/osutil"
11
12
"github.com/lima-vm/lima/pkg/sshutil"
12
13
"github.com/lima-vm/lima/pkg/store"
@@ -51,18 +52,22 @@ func copyAction(cmd *cobra.Command, args []string) error {
51
52
return err
52
53
}
53
54
instDirs := make (map [string ]string )
55
+ scpFlags := []string {}
54
56
scpArgs := []string {}
55
57
debug , err := cmd .Flags ().GetBool ("debug" )
56
58
if err != nil {
57
59
return err
58
60
}
59
61
if debug {
60
- scpArgs = append (scpArgs , "-v" )
62
+ scpFlags = append (scpFlags , "-v" )
61
63
}
62
64
if recursive {
63
- scpArgs = append (scpArgs , "-r" )
65
+ scpFlags = append (scpFlags , "-r" )
66
+ }
67
+ legacySSH := false
68
+ if sshutil .DetectOpenSSHVersion ().LessThan (* semver .New ("8.0.0" )) {
69
+ legacySSH = true
64
70
}
65
- scpArgs = append (scpArgs , "-3" , "--" )
66
71
for _ , arg := range args {
67
72
path := strings .Split (arg , ":" )
68
73
switch len (path ) {
@@ -80,12 +85,22 @@ func copyAction(cmd *cobra.Command, args []string) error {
80
85
if inst .Status == store .StatusStopped {
81
86
return fmt .Errorf ("instance %q is stopped, run `limactl start %s` to start the instance" , instName , instName )
82
87
}
83
- scpArgs = append (
scpArgs ,
fmt .
Sprintf (
"scp://%[email protected] :%d/%s" ,
u .
Username ,
inst .
SSHLocalPort ,
path [
1 ]))
88
+ if legacySSH {
89
+ scpFlags = append (scpFlags , "-P" , fmt .Sprintf ("%d" , inst .SSHLocalPort ))
90
+ scpArgs = append (
scpArgs ,
fmt .
Sprintf (
"%[email protected] :%s" ,
u .
Username ,
path [
1 ]))
91
+ } else {
92
+ scpArgs = append (
scpArgs ,
fmt .
Sprintf (
"scp://%[email protected] :%d/%s" ,
u .
Username ,
inst .
SSHLocalPort ,
path [
1 ]))
93
+ }
84
94
instDirs [instName ] = inst .Dir
85
95
default :
86
96
return fmt .Errorf ("path %q contains multiple colons" , arg )
87
97
}
88
98
}
99
+ if legacySSH && len (instDirs ) > 1 {
100
+ return fmt .Errorf ("More than one (instance) host is involved in this command, this is only supported for openSSH v8.0 or higher" )
101
+ }
102
+ scpFlags = append (scpFlags , "-3" , "--" )
103
+ scpArgs = append (scpFlags , scpArgs ... )
89
104
90
105
var sshOpts []string
91
106
if len (instDirs ) == 1 {
0 commit comments