|
8 | 8 | "strings" |
9 | 9 |
|
10 | 10 | "github.com/coreos/go-semver/semver" |
11 | | - "github.com/lima-vm/lima/pkg/osutil" |
12 | 11 | "github.com/lima-vm/lima/pkg/sshutil" |
13 | 12 | "github.com/lima-vm/lima/pkg/store" |
14 | 13 | "github.com/sirupsen/logrus" |
@@ -48,11 +47,7 @@ func copyAction(cmd *cobra.Command, args []string) error { |
48 | 47 | if err != nil { |
49 | 48 | return err |
50 | 49 | } |
51 | | - u, err := osutil.LimaUser(false) |
52 | | - if err != nil { |
53 | | - return err |
54 | | - } |
55 | | - instDirs := make(map[string]string) |
| 50 | + instances := make(map[string]*store.Instance) |
56 | 51 | scpFlags := []string{} |
57 | 52 | scpArgs := []string{} |
58 | 53 | debug, err := cmd.Flags().GetBool("debug") |
@@ -85,28 +80,28 @@ func copyAction(cmd *cobra.Command, args []string) error { |
85 | 80 | } |
86 | 81 | if legacySSH { |
87 | 82 | scpFlags = append(scpFlags, "-P", fmt.Sprintf("%d", inst.SSHLocalPort)) |
88 | | - scpArgs = append(scpArgs, fmt.Sprintf("%s@127.0.0.1:%s", u.Username, path[1])) |
| 83 | + scpArgs = append(scpArgs, fmt.Sprintf("%s@127.0.0.1:%s", *inst.Config.User.Name, path[1])) |
89 | 84 | } else { |
90 | | - scpArgs = append(scpArgs, fmt.Sprintf("scp://%s@127.0.0.1:%d/%s", u.Username, inst.SSHLocalPort, path[1])) |
| 85 | + scpArgs = append(scpArgs, fmt.Sprintf("scp://%s@127.0.0.1:%d/%s", *inst.Config.User.Name, inst.SSHLocalPort, path[1])) |
91 | 86 | } |
92 | | - instDirs[instName] = inst.Dir |
| 87 | + instances[instName] = inst |
93 | 88 | default: |
94 | 89 | return fmt.Errorf("path %q contains multiple colons", arg) |
95 | 90 | } |
96 | 91 | } |
97 | | - if legacySSH && len(instDirs) > 1 { |
| 92 | + if legacySSH && len(instances) > 1 { |
98 | 93 | return fmt.Errorf("more than one (instance) host is involved in this command, this is only supported for openSSH v8.0 or higher") |
99 | 94 | } |
100 | 95 | scpFlags = append(scpFlags, "-3", "--") |
101 | 96 | scpArgs = append(scpFlags, scpArgs...) |
102 | 97 |
|
103 | 98 | var sshOpts []string |
104 | | - if len(instDirs) == 1 { |
| 99 | + if len(instances) == 1 { |
105 | 100 | // Only one (instance) host is involved; we can use the instance-specific |
106 | 101 | // arguments such as ControlPath. This is preferred as we can multiplex |
107 | 102 | // sessions without re-authenticating (MaxSessions permitting). |
108 | | - for _, instDir := range instDirs { |
109 | | - sshOpts, err = sshutil.SSHOpts(instDir, false, false, false, false) |
| 103 | + for _, inst := range instances { |
| 104 | + sshOpts, err = sshutil.SSHOpts(inst.Dir, *inst.Config.User.Name, false, false, false, false) |
110 | 105 | if err != nil { |
111 | 106 | return err |
112 | 107 | } |
|
0 commit comments