From d857c9ccbb2e256569d0d9ebd462a6ba630e5e49 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 23 Aug 2013 19:31:33 -0700 Subject: [PATCH] builder/amazon/chroot: implement UploadDir for chroot communicator --- builder/amazon/chroot/communicator.go | 32 +++++++++++++++++++++++++++ communicator/ssh/communicator.go | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/builder/amazon/chroot/communicator.go b/builder/amazon/chroot/communicator.go index e0bc5613f..111adb42e 100644 --- a/builder/amazon/chroot/communicator.go +++ b/builder/amazon/chroot/communicator.go @@ -70,6 +70,38 @@ func (c *Communicator) Upload(dst string, r io.Reader) error { 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 { + return err + } + + path, err := filepath.Rel(src, fullPath) + if err != nil { + return err + } + + for _, e := range exclude { + if e == path { + log.Printf("Skipping excluded file: %s", path) + return nil + } + } + + dstPath := filepath.Join(dst, path) + f, err := os.Open(fullPath) + if err != nil { + return err + } + defer f.Close() + + return c.Upload(dstPath, f) + } + + log.Printf("Uploading directory '%s' to '%s'", src, dst) + return filepath.Walk(src, walkFn) +} + 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/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index c59b91892..3332108d6 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -204,6 +204,10 @@ func (c *comm) Upload(path string, input io.Reader) error { return nil } +func (c *comm) UploadDir(dst string, src string, excl []string) error { + return nil +} + func (c *comm) Download(string, io.Writer) error { panic("not implemented yet") }