diff --git a/packer/communicator_mock.go b/packer/communicator_mock.go index b6127015f..30539f6f1 100644 --- a/packer/communicator_mock.go +++ b/packer/communicator_mock.go @@ -20,6 +20,10 @@ type MockCommunicator struct { UploadPath string UploadData string + UploadDirDst string + UploadDirSrc string + UploadDirExclude []string + DownloadCalled bool DownloadPath string DownloadData string @@ -78,7 +82,11 @@ func (c *MockCommunicator) Upload(path string, r io.Reader) error { return nil } -func (c *MockCommunicator) UploadDir(string, string, []string) error { +func (c *MockCommunicator) UploadDir(dst string, src string, excl []string) error { + c.UploadDirDst = dst + c.UploadDirSrc = src + c.UploadDirExclude = excl + return nil } diff --git a/packer/rpc/communicator.go b/packer/rpc/communicator.go index f5f99c8e9..21b507f0b 100644 --- a/packer/rpc/communicator.go +++ b/packer/rpc/communicator.go @@ -44,6 +44,12 @@ type CommunicatorUploadArgs struct { ReaderAddress string } +type CommunicatorUploadDirArgs struct { + Dst string + Src string + Exclude []string +} + func Communicator(client *rpc.Client) *communicator { return &communicator{client} } @@ -124,7 +130,19 @@ func (c *communicator) Upload(path string, r io.Reader) (err error) { } func (c *communicator) UploadDir(dst string, src string, exclude []string) error { - return nil + args := &CommunicatorUploadDirArgs{ + Dst: dst, + Src: src, + Exclude: exclude, + } + + var reply error + err := c.client.Call("Communicator.UploadDir", args, &reply) + if err == nil { + err = reply + } + + return err } func (c *communicator) Download(path string, w io.Writer) (err error) { @@ -227,6 +245,10 @@ func (c *CommunicatorServer) Upload(args *CommunicatorUploadArgs, reply *interfa return } +func (c *CommunicatorServer) UploadDir(args *CommunicatorUploadDirArgs, reply *error) error { + return c.c.UploadDir(args.Dst, args.Src, args.Exclude) +} + func (c *CommunicatorServer) Download(args *CommunicatorDownloadArgs, reply *interface{}) (err error) { writerC, err := net.Dial("tcp", args.WriterAddress) if err != nil { diff --git a/packer/rpc/communicator_test.go b/packer/rpc/communicator_test.go index cf202ad8b..f6013a061 100644 --- a/packer/rpc/communicator_test.go +++ b/packer/rpc/communicator_test.go @@ -5,6 +5,7 @@ import ( "github.com/mitchellh/packer/packer" "io" "net/rpc" + "reflect" "testing" ) @@ -104,6 +105,27 @@ func TestCommunicatorRPC(t *testing.T) { t.Fatalf("bad: %s", c.UploadData) } + // Test that we can upload directories + dirDst := "foo" + dirSrc := "bar" + dirExcl := []string{"foo"} + err = remote.UploadDir(dirDst, dirSrc, dirExcl) + if err != nil { + t.Fatalf("err: %s", err) + } + + if c.UploadDirDst != dirDst { + t.Fatalf("bad: %s", c.UploadDirDst) + } + + if c.UploadDirSrc != dirSrc { + t.Fatalf("bad: %s", c.UploadDirSrc) + } + + if !reflect.DeepEqual(c.UploadDirExclude, dirExcl) { + t.Fatalf("bad: %#v", c.UploadDirExclude) + } + // Test that we can download things downloadR, downloadW := io.Pipe() downloadDone := make(chan bool)