From 73c5aec24d0a504ecfbae038b4b7effb54adb929 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Thu, 26 Sep 2013 00:31:07 -0700 Subject: [PATCH] notes/reorg. --- builder/amazon/chroot/communicator.go | 32 ++++++++++++------------ builder/amazon/chroot/step_copy_files.go | 6 +++++ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/builder/amazon/chroot/communicator.go b/builder/amazon/chroot/communicator.go index d434da8f1..b81300563 100644 --- a/builder/amazon/chroot/communicator.go +++ b/builder/amazon/chroot/communicator.go @@ -52,22 +52,6 @@ func (c *Communicator) Start(cmd *packer.RemoteCmd) error { return nil } -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) - if err != nil { - return err - } - defer f.Close() - - if _, err := io.Copy(f, r); err != nil { - return err - } - - return nil -} - func (c *Communicator) UploadDir(dst string, src string, exclude []string) error { walkFn := func(fullPath string, info os.FileInfo, err error) error { if err != nil { @@ -100,6 +84,22 @@ func (c *Communicator) UploadDir(dst string, src string, exclude []string) error return filepath.Walk(src, walkFn) } +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) + if err != nil { + return err + } + defer f.Close() + + if _, err := io.Copy(f, r); err != nil { + return err + } + + return nil +} + func (c *Communicator) Download(src string, w io.Writer) error { src = filepath.Join(c.Chroot, src) log.Printf("Downloading from chroot dir: %s", src) diff --git a/builder/amazon/chroot/step_copy_files.go b/builder/amazon/chroot/step_copy_files.go index d729ee234..d383103a4 100644 --- a/builder/amazon/chroot/step_copy_files.go +++ b/builder/amazon/chroot/step_copy_files.go @@ -68,6 +68,12 @@ func (s *StepCopyFiles) CleanupFunc(multistep.StateBag) error { return nil } +/* TODO: move to util file. + * change prototype to + func copySingle(dst string, src string, copyCommand string) error + * I think we should switch to cp for copying files, then allow specifying a copy_files_command or something. +Maybe we should just do a execute_wrapper that allows you to wrap every command... +*/ func (s *StepCopyFiles) copySingle(dst, src string) error { // Stat the src file so we can copy the mode later srcInfo, err := os.Stat(src)