ssh communicator works

This commit is contained in:
Megan Marsh 2017-10-03 16:36:27 -07:00
parent a5e6134819
commit b3cc90125d
1 changed files with 4 additions and 8 deletions

View File

@ -534,11 +534,8 @@ func (c *comm) scpUploadSession(path string, input io.Reader, fi *os.FileInfo) e
target_file := filepath.Base(path)
// find out if it's a directory
testDirectoryCommand := fmt.Sprintf("if [ -d \"%s\" ]; then echo directory; fi", path)
testDirectoryCommand := fmt.Sprintf(`test -d "%s"`, 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)
@ -546,10 +543,9 @@ func (c *comm) scpUploadSession(path string, input io.Reader, fi *os.FileInfo) e
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")
cmd.Wait()
if cmd.ExitStatus == 0 {
log.Printf("path is a directory; copying file into directory.")
target_dir = path
target_file = filepath.Base((*fi).Name())
}