-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from mook-as/copy-controlpath
copy: use SSHArgs if copying to a single remote host.
- Loading branch information
Showing
2 changed files
with
26 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,12 +36,8 @@ func copyAction(clicontext *cli.Context) error { | |
return err | ||
} | ||
|
||
const useDotSSH = false | ||
args, err := sshutil.CommonArgs(useDotSSH) | ||
if err != nil { | ||
return err | ||
} | ||
args = append(args, "-3", "--") | ||
instDirs := make(map[string]string) | ||
args := []string{"-3", "--"} | ||
for _, arg := range clicontext.Args().Slice() { | ||
path := strings.Split(arg, ":") | ||
switch len(path) { | ||
|
@@ -60,15 +56,36 @@ func copyAction(clicontext *cli.Context) error { | |
return fmt.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName) | ||
} | ||
args = append(args, fmt.Sprintf("scp://%[email protected]:%d/%s", u.Username, inst.SSHLocalPort, path[1])) | ||
instDirs[instName] = inst.Dir | ||
default: | ||
return fmt.Errorf("Path %q contains multiple colons", arg) | ||
} | ||
} | ||
cmd := exec.Command(arg0, args...) | ||
|
||
sshArgs := []string{} | ||
if len(instDirs) == 1 { | ||
// Only one (instance) host is involved; we can use the instance-specific | ||
// arguments such as ControlPath. This is preferred as we can multiplex | ||
// sessions without re-authenticating (MaxSessions permitting). | ||
for _, instDir := range instDirs { | ||
sshArgs, err = sshutil.SSHArgs(instDir, false) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} else { | ||
// Copying among multiple hosts; we can't pass in host-specific options. | ||
sshArgs, err = sshutil.CommonArgs(false) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
cmd := exec.Command(arg0, append(sshArgs, args...)...) | ||
cmd.Stdin = os.Stdin | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
logrus.Debugf("executing scp (may take a long)): %+v", cmd.Args) | ||
logrus.Debugf("executing scp (may take a long time)): %+v", cmd.Args) | ||
|
||
// TODO: use syscall.Exec directly (results in losing tty?) | ||
return cmd.Run() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters