From 93c2de0af3a0213c058f6d9c9033cda13a6da381 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Fri, 27 Sep 2013 02:11:28 +0000 Subject: [PATCH] fix chroot Upload command. --- builder/amazon/chroot/communicator.go | 15 ++++++--------- builder/amazon/chroot/copy_files.go | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/builder/amazon/chroot/communicator.go b/builder/amazon/chroot/communicator.go index 2b2e1cada..879d5e5a5 100644 --- a/builder/amazon/chroot/communicator.go +++ b/builder/amazon/chroot/communicator.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/mitchellh/packer/packer" "io" + "io/ioutil" "log" "os" "os/exec" @@ -57,17 +58,13 @@ func (c *Communicator) Start(cmd *packer.RemoteCmd) error { func (c *Communicator) Upload(dst string, r io.Reader) error { dst = filepath.Join(c.Chroot, dst) log.Printf("Uploading to chroot dir: %s", dst) - f, err := os.Create(dst) + tf, err := ioutil.TempFile("", "packer-amazon-chroot") if err != nil { - return err + return fmt.Errorf("Error preparing shell script: %s", err) } - defer f.Close() - - if _, err := io.Copy(f, r); err != nil { - return err - } - - return nil + defer os.Remove(tf.Name()) + io.Copy(tf, r) + return copySingle(dst, tf.Name(), c.CopyCommand) } func (c *Communicator) UploadDir(dst string, src string, exclude []string) error { diff --git a/builder/amazon/chroot/copy_files.go b/builder/amazon/chroot/copy_files.go index f44c7da96..16d0a82f6 100644 --- a/builder/amazon/chroot/copy_files.go +++ b/builder/amazon/chroot/copy_files.go @@ -9,7 +9,7 @@ import ( func copySingle(dest string, src string, copyCommand string) error { cpCommand := fmt.Sprintf("%s %s %s", copyCommand, src, dest) localCmd := exec.Command("/bin/sh", "-c", cpCommand) - log.Println(localCmd.Args) + log.Printf("Executing copy: %s %#v", localCmd.Path, localCmd.Args) if err := localCmd.Run(); err != nil { return err }