This repository has been archived by the owner on Sep 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 #4388 from docker/4302-scp-commandline-win
Fix argument escaping for scp on Windows
- Loading branch information
Showing
3 changed files
with
61 additions
and
21 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
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 |
---|---|---|
@@ -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) | ||
} |
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 |
---|---|---|
@@ -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) | ||
} |