remove attempt to discover whether destination is a directory from upload function in various communicators

This commit is contained in:
Megan Marsh 2018-04-10 08:13:06 -07:00
parent 39845915ca
commit ee1ff3132d
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 // 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 { 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 // command format: docker cp /path/to/infile containerid:/path/to/outfile
log.Printf("Copying to %s on container %s.", dst, c.ContainerID) 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 { func (c *comm) sftpUploadFile(path string, input io.Reader, client *sftp.Client, fi *os.FileInfo) error {
log.Printf("[DEBUG] sftp: uploading %s", path) 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) f, err := client.Create(path)
if err != nil { if err != nil {
return err 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_dir := filepath.Dir(path)
target_file := filepath.Base(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"). // On windows, filepath.Dir uses backslash separators (ie. "\tmp").
// This does not work when the target host is unix. Switch to forward slash // This does not work when the target host is unix. Switch to forward slash
// which works for unix and windows // which works for unix and windows