-
Notifications
You must be signed in to change notification settings - Fork 604
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 #386 from davidcassany/fix_scp_command_for_old_ope…
…nssh Adapt scp source and target arguments for old openssh
- Loading branch information
Showing
2 changed files
with
21 additions
and
6 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 |
---|---|---|
|
@@ -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" | ||
|
@@ -51,18 +52,22 @@ func copyAction(cmd *cobra.Command, args []string) error { | |
return err | ||
} | ||
instDirs := make(map[string]string) | ||
scpFlags := []string{} | ||
scpArgs := []string{} | ||
debug, err := cmd.Flags().GetBool("debug") | ||
if err != nil { | ||
return err | ||
} | ||
if debug { | ||
scpArgs = append(scpArgs, "-v") | ||
scpFlags = append(scpFlags, "-v") | ||
} | ||
if recursive { | ||
scpArgs = append(scpArgs, "-r") | ||
scpFlags = append(scpFlags, "-r") | ||
} | ||
legacySSH := false | ||
if sshutil.DetectOpenSSHVersion().LessThan(*semver.New("8.0.0")) { | ||
legacySSH = true | ||
} | ||
scpArgs = append(scpArgs, "-3", "--") | ||
for _, arg := range args { | ||
path := strings.Split(arg, ":") | ||
switch len(path) { | ||
|
@@ -80,12 +85,22 @@ 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://%[email protected]:%d/%s", u.Username, inst.SSHLocalPort, path[1])) | ||
if legacySSH { | ||
scpFlags = append(scpFlags, "-P", fmt.Sprintf("%d", inst.SSHLocalPort)) | ||
scpArgs = append(scpArgs, fmt.Sprintf("%[email protected]:%s", u.Username, path[1])) | ||
} else { | ||
scpArgs = append(scpArgs, 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) | ||
} | ||
} | ||
if legacySSH && len(instDirs) > 1 { | ||
return fmt.Errorf("More than one (instance) host is involved in this command, this is only supported for openSSH v8.0 or higher") | ||
} | ||
scpFlags = append(scpFlags, "-3", "--") | ||
scpArgs = append(scpFlags, scpArgs...) | ||
|
||
var sshOpts []string | ||
if len(instDirs) == 1 { | ||
|
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