@@ -36,12 +36,8 @@ func copyAction(clicontext *cli.Context) error {
36
36
return err
37
37
}
38
38
39
- const useDotSSH = false
40
- args , err := sshutil .CommonArgs (useDotSSH )
41
- if err != nil {
42
- return err
43
- }
44
- args = append (args , "-3" , "--" )
39
+ instDirs := make (map [string ]string )
40
+ args := []string {"-3" , "--" }
45
41
for _ , arg := range clicontext .Args ().Slice () {
46
42
path := strings .Split (arg , ":" )
47
43
switch len (path ) {
@@ -60,15 +56,36 @@ func copyAction(clicontext *cli.Context) error {
60
56
return fmt .Errorf ("instance %q is stopped, run `limactl start %s` to start the instance" , instName , instName )
61
57
}
62
58
args = append (
args ,
fmt .
Sprintf (
"scp://%[email protected] :%d/%s" ,
u .
Username ,
inst .
SSHLocalPort ,
path [
1 ]))
59
+ instDirs [instName ] = inst .Dir
63
60
default :
64
61
return fmt .Errorf ("Path %q contains multiple colons" , arg )
65
62
}
66
63
}
67
- cmd := exec .Command (arg0 , args ... )
64
+
65
+ sshArgs := []string {}
66
+ if len (instDirs ) == 1 {
67
+ // Only one (instance) host is involved; we can use the instance-specific
68
+ // arguments such as ControlPath. This is preferred as we can multiplex
69
+ // sessions without re-authenticating (MaxSessions permitting).
70
+ for _ , instDir := range instDirs {
71
+ sshArgs , err = sshutil .SSHArgs (instDir , false )
72
+ if err != nil {
73
+ return err
74
+ }
75
+ }
76
+ } else {
77
+ // Copying among multiple hosts; we can't pass in host-specific options.
78
+ sshArgs , err = sshutil .CommonArgs (false )
79
+ if err != nil {
80
+ return err
81
+ }
82
+ }
83
+
84
+ cmd := exec .Command (arg0 , append (sshArgs , args ... )... )
68
85
cmd .Stdin = os .Stdin
69
86
cmd .Stdout = os .Stdout
70
87
cmd .Stderr = os .Stderr
71
- logrus .Debugf ("executing scp (may take a long)): %+v" , cmd .Args )
88
+ logrus .Debugf ("executing scp (may take a long time )): %+v" , cmd .Args )
72
89
73
90
// TODO: use syscall.Exec directly (results in losing tty?)
74
91
return cmd .Run ()
0 commit comments