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

Commit

Permalink
Merge pull request #4388 from docker/4302-scp-commandline-win
Browse files Browse the repository at this point in the history
Fix argument escaping for scp on Windows
  • Loading branch information
dgageot authored Feb 10, 2018
2 parents d8b1195 + 7055c02 commit e02ab45
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
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)
}

0 comments on commit e02ab45

Please sign in to comment.