|
|
|
|
@ -333,15 +333,6 @@ func checkSCPStatus(r *bufio.Reader) error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func scpUploadFile(dst string, src io.Reader, w io.Writer, r *bufio.Reader, fi *os.FileInfo) error {
|
|
|
|
|
// Create a temporary file where we can copy the contents of the src
|
|
|
|
|
// so that we can determine the length, since SCP is length-prefixed.
|
|
|
|
|
tf, err := ioutil.TempFile("", "packer-upload")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("Error creating temporary file for upload: %s", err)
|
|
|
|
|
}
|
|
|
|
|
defer os.Remove(tf.Name())
|
|
|
|
|
defer tf.Close()
|
|
|
|
|
|
|
|
|
|
var mode os.FileMode
|
|
|
|
|
var size int64
|
|
|
|
|
|
|
|
|
|
@ -349,6 +340,15 @@ func scpUploadFile(dst string, src io.Reader, w io.Writer, r *bufio.Reader, fi *
|
|
|
|
|
mode = (*fi).Mode().Perm()
|
|
|
|
|
size = (*fi).Size()
|
|
|
|
|
} else {
|
|
|
|
|
// Create a temporary file where we can copy the contents of the src
|
|
|
|
|
// so that we can determine the length, since SCP is length-prefixed.
|
|
|
|
|
tf, err := ioutil.TempFile("", "packer-upload")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("Error creating temporary file for upload: %s", err)
|
|
|
|
|
}
|
|
|
|
|
defer os.Remove(tf.Name())
|
|
|
|
|
defer tf.Close()
|
|
|
|
|
|
|
|
|
|
mode = 0644
|
|
|
|
|
|
|
|
|
|
log.Println("Copying input data into temporary file so we can read the length")
|
|
|
|
|
@ -373,19 +373,19 @@ func scpUploadFile(dst string, src io.Reader, w io.Writer, r *bufio.Reader, fi *
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size = tfi.Size()
|
|
|
|
|
src = tf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start the protocol
|
|
|
|
|
log.Println("Beginning file upload...")
|
|
|
|
|
|
|
|
|
|
perms := fmt.Sprintf("C%04o", mode)
|
|
|
|
|
log.Printf("[DEBUG] Uploading %s: perms=%s size=%d", dst, perms, size)
|
|
|
|
|
|
|
|
|
|
fmt.Fprintln(w, perms, size, dst)
|
|
|
|
|
if err := checkSCPStatus(r); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, err := io.Copy(w, tf); err != nil {
|
|
|
|
|
if _, err := io.CopyN(w, src, size); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|