Skip to content

Commit

Permalink
Adapt scp source and target arguments for old openssh
Browse files Browse the repository at this point in the history
This commit does not make use of URIs in scp command when openssh
versions is smaller than v8.

Signed-off-by: David Cassany <dcassany@suse.com>
  • Loading branch information
davidcassany committed Nov 5, 2021
1 parent 9029b1c commit a71c3a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion cmd/limactl/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"strings"

"github.com/coreos/go-semver/semver"
"github.com/lima-vm/lima/pkg/osutil"
"github.com/lima-vm/lima/pkg/sshutil"
"github.com/lima-vm/lima/pkg/store"
Expand Down Expand Up @@ -63,6 +64,7 @@ func copyAction(cmd *cobra.Command, args []string) error {
scpArgs = append(scpArgs, "-r")
}
scpArgs = append(scpArgs, "-3", "--")
flagsEndIdx := len(scpArgs) - 1
for _, arg := range args {
path := strings.Split(arg, ":")
switch len(path) {
Expand All @@ -80,7 +82,13 @@ func copyAction(cmd *cobra.Command, args []string) error {
if inst.Status == store.StatusStopped {
return fmt.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName)
}
scpArgs = append(scpArgs, fmt.Sprintf("scp://%s@127.0.0.1:%d/%s", u.Username, inst.SSHLocalPort, path[1]))
// Only OpenSSH version 8.0 and later support using source and target as scp:// URIs
if !sshutil.DetectOpenSSHVersion().LessThan(*semver.New("8.0.0")) {
scpArgs = append(scpArgs, fmt.Sprintf("scp://%s@127.0.0.1:%d/%s", u.Username, inst.SSHLocalPort, path[1]))
} else {
scpArgs = append(scpArgs[:flagsEndIdx], append([]string{"-P", fmt.Sprintf("%d", inst.SSHLocalPort)}, scpArgs[flagsEndIdx:]...)...)
scpArgs = append(scpArgs, fmt.Sprintf("%s@127.0.0.1:%s", u.Username, path[1]))
}
instDirs[instName] = inst.Dir
default:
return fmt.Errorf("path %q contains multiple colons", arg)
Expand Down
4 changes: 2 additions & 2 deletions pkg/sshutil/sshutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func CommonOpts(useDotSSH bool) ([]string, error) {

sshInfo.Do(func() {
sshInfo.aesAccelerated = detectAESAcceleration()
sshInfo.openSSHVersion = detectOpenSSHVersion()
sshInfo.openSSHVersion = DetectOpenSSHVersion()
})

// Only OpenSSH version 8.1 and later support adding ciphers to the front of the default set
Expand Down Expand Up @@ -246,7 +246,7 @@ func ParseOpenSSHVersion(version []byte) *semver.Version {
return &semver.Version{}
}

func detectOpenSSHVersion() semver.Version {
func DetectOpenSSHVersion() semver.Version {
var (
v semver.Version
stderr bytes.Buffer
Expand Down

0 comments on commit a71c3a9

Please sign in to comment.