Merge pull request #6124 from hashicorp/remove_directory_test

remove attempt to discover whether destination is a directory from up…
This commit is contained in:
M. Marsh 2018-04-18 11:52:18 -07:00 committed by GitHub
commit 7a7386e800
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 65 deletions

View File

@ -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)

View File

@ -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