Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Fix argument escaping for scp on Windows #4388

Merged
merged 1 commit into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions commands/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os/exec"
"strings"

"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/persist"
)
Expand Down Expand Up @@ -54,26 +53,6 @@ func (s *storeHostInfoLoader) load(name string) (HostInfo, error) {
return host.Driver, nil
}

func cmdScp(c CommandLine, api libmachine.API) error {
args := c.Args()
if len(args) != 2 {
c.ShowHelp()
return errWrongNumberArguments
}

src := args[0]
dest := args[1]

hostInfoLoader := &storeHostInfoLoader{api}

cmd, err := getScpCmd(src, dest, c.Bool("recursive"), c.Bool("delta"), c.Bool("quiet"), hostInfoLoader)
if err != nil {
return err
}

return runCmdWithStdIo(*cmd)
}

func getScpCmd(src, dest string, recursive bool, delta bool, quiet bool, hostInfoLoader HostInfoLoader) (*exec.Cmd, error) {
var cmdPath string
var err error
Expand Down
27 changes: 27 additions & 0 deletions commands/scp_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// +build !windows

package commands

import (
"github.com/docker/machine/libmachine"
)

func cmdScp(c CommandLine, api libmachine.API) error {
args := c.Args()
if len(args) != 2 {
c.ShowHelp()
return errWrongNumberArguments
}

src := args[0]
dest := args[1]

hostInfoLoader := &storeHostInfoLoader{api}

cmd, err := getScpCmd(src, dest, c.Bool("recursive"), c.Bool("delta"), c.Bool("quiet"), hostInfoLoader)
if err != nil {
return err
}

return runCmdWithStdIo(*cmd)
}
34 changes: 34 additions & 0 deletions commands/scp_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package commands

import (
"fmt"
"strings"
"syscall"

"github.com/docker/machine/libmachine"
)

func cmdScp(c CommandLine, api libmachine.API) error {
args := c.Args()
if len(args) != 2 {
c.ShowHelp()
return errWrongNumberArguments
}

src := args[0]
dest := args[1]

hostInfoLoader := &storeHostInfoLoader{api}

cmd, err := getScpCmd(src, dest, c.Bool("recursive"), c.Bool("delta"), c.Bool("quiet"), hostInfoLoader)
if err != nil {
return err
}

// Default argument escaping is not valid for scp.exe with quoted arguments, so we do it ourselves
// see golang/go#15566
cmd.SysProcAttr = &syscall.SysProcAttr{}
cmd.SysProcAttr.CmdLine = fmt.Sprintf("%s %s", cmd.Path, strings.Join(cmd.Args, " "))

return runCmdWithStdIo(*cmd)
}