From b3cc90125dde7fbec29d6c9616df4167efe5f968 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 3 Oct 2017 16:36:27 -0700 Subject: [PATCH] ssh communicator works --- communicator/ssh/communicator.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index 827925f2c..3ec2d1aba 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -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()) }