diff --git a/builder/amazon/chroot/builder_test.go b/builder/amazon/chroot/builder_test.go index 2f13bae54..6bdf7dc28 100644 --- a/builder/amazon/chroot/builder_test.go +++ b/builder/amazon/chroot/builder_test.go @@ -82,3 +82,14 @@ func TestBuilderPrepare_SourceAmi(t *testing.T) { t.Errorf("err: %s", err) } } + +func TestBuilderPrepare_CommandWrapper(t *testing.T) { + b := &Builder{} + config := testConfig() + + config["command_wrapper"] = "echo hi; {{.Command}}" + err := b.Prepare(config) + if err != nil { + t.Errorf("err: %s", err) + } +} diff --git a/builder/amazon/chroot/copy_files_test.go b/builder/amazon/chroot/copy_files_test.go index a9da8d742..2dccbf0bc 100644 --- a/builder/amazon/chroot/copy_files_test.go +++ b/builder/amazon/chroot/copy_files_test.go @@ -18,8 +18,10 @@ func TestCopyFile(t *testing.T) { if _, err = first.WriteString(payload); err != nil { t.Fatalf("Couldn't write payload to first file.") } + first.Sync() - if err := copySingle(newName, first.Name(), "cp"); err != nil { + cmd := ShellCommand(fmt.Sprintf("cp %s %s", first.Name(), newName)) + if err := cmd.Run(); err != nil { t.Fatalf("Couldn't copy file") } defer os.Remove(newName) diff --git a/builder/amazon/chroot/step_chroot_provision.go b/builder/amazon/chroot/step_chroot_provision.go index 7375ecad2..59a95f45c 100644 --- a/builder/amazon/chroot/step_chroot_provision.go +++ b/builder/amazon/chroot/step_chroot_provision.go @@ -13,7 +13,7 @@ type StepChrootProvision struct { } type WrappedCommandTemplate struct { - command string + Command string } func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction { @@ -26,7 +26,7 @@ func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction } wrappedCommand := func(command string) *exec.Cmd { wrapped, err := config.tpl.Process(config.CommandWrapper, &WrappedCommandTemplate{ - command: command, + Command: command, }) if err != nil { ui.Error(err.Error()) diff --git a/builder/amazon/chroot/step_copy_files.go b/builder/amazon/chroot/step_copy_files.go index 80a7b135e..e22301369 100644 --- a/builder/amazon/chroot/step_copy_files.go +++ b/builder/amazon/chroot/step_copy_files.go @@ -60,7 +60,6 @@ func (s *StepCopyFiles) CleanupFunc(state multistep.StateBag) error { for _, file := range s.files { log.Printf("Removing: %s", file) localCmd := wrappedCommand(fmt.Sprintf("rm -f %s", file)) - log.Println(localCmd.Args) if err := localCmd.Run(); err != nil { return err } diff --git a/builder/amazon/chroot/step_mount_device.go b/builder/amazon/chroot/step_mount_device.go index f9a823623..4cce60f10 100644 --- a/builder/amazon/chroot/step_mount_device.go +++ b/builder/amazon/chroot/step_mount_device.go @@ -59,7 +59,7 @@ func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction { ui.Say("Mounting the root device...") stderr := new(bytes.Buffer) mountCommand := fmt.Sprintf("mount %s %s", device, mountPath) - wrappedCommand := state.Get("wrappedCommand").(Command) + wrappedCommand := state.Get("wrappedCommand").(*Command) cmd := wrappedCommand(mountCommand) cmd.Stderr = stderr if err := cmd.Run(); err != nil {