From ee1ff3132d22035faeefefb81797f61421b963bd Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 10 Apr 2018 08:13:06 -0700 Subject: [PATCH] remove attempt to discover whether destination is a directory from upload function in various communicators --- builder/docker/communicator.go | 16 ----------- communicator/ssh/communicator.go | 49 -------------------------------- 2 files changed, 65 deletions(-) diff --git a/builder/docker/communicator.go b/builder/docker/communicator.go index 7b0ecae07..e898ecd1c 100644 --- a/builder/docker/communicator.go +++ b/builder/docker/communicator.go @@ -105,22 +105,6 @@ func (c *Communicator) uploadReader(dst string, src io.Reader) error { // uploadFile uses docker cp to copy the file from the host to the container func (c *Communicator) uploadFile(dst string, src io.Reader, fi *os.FileInfo) error { - // find out if it's a directory - testDirectoryCommand := fmt.Sprintf(`test -d "%s"`, dst) - cmd := &packer.RemoteCmd{Command: testDirectoryCommand} - - err := c.Start(cmd) - - if err != nil { - log.Printf("Unable to check whether remote path is a dir: %s", err) - return err - } - cmd.Wait() - if cmd.ExitStatus == 0 { - log.Printf("path is a directory; copying file into directory.") - dst = filepath.Join(dst, filepath.Base((*fi).Name())) - } - // command format: docker cp /path/to/infile containerid:/path/to/outfile log.Printf("Copying to %s on container %s.", dst, c.ContainerID) diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index 218c11be6..6545d1d5c 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -410,27 +410,6 @@ func (c *comm) sftpUploadSession(path string, input io.Reader, fi *os.FileInfo) func (c *comm) sftpUploadFile(path string, input io.Reader, client *sftp.Client, fi *os.FileInfo) error { log.Printf("[DEBUG] sftp: uploading %s", path) - - // find out if destination is a directory (this is to replicate rsync behavior) - testDirectoryCommand := fmt.Sprintf(`test -d "%s"`, path) - - cmd := &packer.RemoteCmd{ - Command: testDirectoryCommand, - } - - err := c.Start(cmd) - - if err != nil { - log.Printf("[ERROR] Unable to check whether remote path is a dir: %s", err) - return err - } - cmd.Wait() - if cmd.ExitStatus == 0 { - return fmt.Errorf( - "Destination path (%s) is a directory that already exists. "+ - "Please ensure the destination is writable.", path) - } - f, err := client.Create(path) if err != nil { return err @@ -586,34 +565,6 @@ 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 destination is a directory (this is to replicate rsync behavior) - testDirectoryCommand := fmt.Sprintf(`test -d "%s"`, path) - var stdout, stderr bytes.Buffer - cmd := &packer.RemoteCmd{ - Command: testDirectoryCommand, - Stdout: &stdout, - Stderr: &stderr, - } - - err := c.Start(cmd) - - if err != nil { - log.Printf("[ERROR] Unable to check whether remote path is a dir: %s", err) - return err - } - cmd.Wait() - if stdout.Len() > 0 { - return fmt.Errorf("%s", stdout.Bytes()) - } - if stderr.Len() > 0 { - return fmt.Errorf("%s", stderr.Bytes()) - } - if cmd.ExitStatus == 0 { - return fmt.Errorf( - "Destination path (%s) is a directory that already exists. "+ - "Please ensure the destination is writable.", path) - } - // On windows, filepath.Dir uses backslash separators (ie. "\tmp"). // This does not work when the target host is unix. Switch to forward slash // which works for unix and windows