implement dir check for ssh communicator

This commit is contained in:
Megan Marsh 2017-10-03 15:55:32 -07:00
parent 35ef7bce5c
commit a5e6134819
2 changed files with 24 additions and 1 deletions

View File

@ -533,6 +533,29 @@ func (c *comm) scpUploadSession(path string, input io.Reader, fi *os.FileInfo) e
target_dir := filepath.Dir(path)
target_file := filepath.Base(path)
// find out if it's a directory
testDirectoryCommand := fmt.Sprintf("if [ -d \"%s\" ]; then echo directory; fi", path)
cmd := &packer.RemoteCmd{Command: testDirectoryCommand}
var buf, buf2 bytes.Buffer
cmd.Stdout = &buf
cmd.Stdout = io.MultiWriter(cmd.Stdout, &buf2)
err := c.Start(cmd)
if err != nil {
log.Printf("Unable to check whether remote path is a dir: %s", err)
return err
}
stdoutToRead := buf2.String()
if strings.Contains(stdoutToRead, "directory") {
log.Printf("upload locale is a directory")
target_dir = path
target_file = filepath.Base((*fi).Name())
}
log.Printf("target_file was %s", target_file)
// On windows, filepath.Dir uses backslash seperators (ie. "\tmp").
// This does not work when the target host is unix. Switch to forward slash
// which works for unix and windows

View File

@ -122,7 +122,7 @@ func runCommand(shell *winrm.Shell, cmd *winrm.Command, rc *packer.RemoteCmd) {
}
// Upload implementation of communicator.Communicator interface
func (c *Communicator) Upload(path string, input io.Reader, _ *os.FileInfo) error {
func (c *Communicator) Upload(path string, input io.Reader, fi *os.FileInfo) error {
wcp, err := c.newCopyClient()
if err != nil {
return err