Merge pull request #7513 from hashicorp/fix_7511

read stderr before we try to read the archive.
This commit is contained in:
Adrien Delorme 2019-04-17 10:55:48 +02:00 committed by GitHub
commit e1220047f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -233,6 +233,11 @@ func (c *Communicator) Download(src string, dst io.Writer) error {
return fmt.Errorf("Failed to open pipe: %s", err)
}
stderrP, err := localCmd.StderrPipe()
if err != nil {
return fmt.Errorf("Failed to open stderr pipe: %s", err)
}
if err = localCmd.Start(); err != nil {
return fmt.Errorf("Failed to start download: %s", err)
}
@ -240,6 +245,16 @@ func (c *Communicator) Download(src string, dst io.Writer) error {
// When you use - to send docker cp to stdout it is streamed as a tar; this
// enables it to work with directories. We don't actually support
// directories in Download() but we still need to handle the tar format.
stderrOut, err := ioutil.ReadAll(stderrP)
if err != nil {
return err
}
if string(stderrOut) != "" {
return fmt.Errorf("Error downloading file: %s", string(stderrOut))
}
archive := tar.NewReader(pipe)
_, err = archive.Next()
if err != nil {