Skip to content

Commit

Permalink
move wrapper definitions around.
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhooker committed Sep 27, 2013
1 parent 39c3051 commit 831d5ca
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
6 changes: 5 additions & 1 deletion builder/amazon/chroot/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type Config struct {
tpl *packer.ConfigTemplate
}

type wrappedCommandTemplate struct {
Command string
}

type Builder struct {
config Config
runner multistep.Runner
Expand Down Expand Up @@ -162,7 +166,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ec2conn := ec2.New(auth, region)

wrappedCommand := func(command string) *exec.Cmd {
wrapped, err := b.config.tpl.Process(b.config.CommandWrapper, &WrappedCommandTemplate{
wrapped, err := b.config.tpl.Process(b.config.CommandWrapper, &wrappedCommandTemplate{
Command: command,
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions builder/amazon/chroot/communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c *Communicator) Upload(dst string, r io.Reader) error {
}
defer os.Remove(tf.Name())
io.Copy(tf, r)
cpCmd := fmt.Sprintf("cp %s %s", dst, tf.Name())
cpCmd := fmt.Sprintf("cp %s %s", tf.Name(), dst)
return (*c.ChrootCmd(cpCmd)).Run()
}

Expand All @@ -90,7 +90,7 @@ func (c *Communicator) UploadDir(dst string, src string, exclude []string) error

chrootDest := filepath.Join(c.Chroot, dst, path)
log.Printf("Uploading to chroot dir: %s", dst)
cpCmd := fmt.Sprintf("cp %s %s", chrootDest, fullPath)
cpCmd := fmt.Sprintf("cp %s %s", fullPath, chrootDest)
return c.ChrootCmd(cpCmd).Run()
}

Expand Down
9 changes: 4 additions & 5 deletions builder/amazon/chroot/step_chroot_provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ import (
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
"os/exec"
)

// StepChrootProvision provisions the instance within a chroot.
type StepChrootProvision struct {
mounts []string
}

type WrappedCommandTemplate struct {
Command string
}

func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction {
hook := state.Get("hook").(packer.Hook)
mountPath := state.Get("mount_path").(string)
ui := state.Get("ui").(packer.Ui)
wrappedCommand := state.Get("wrappedCommand").(Command)
chrootCmd := state.Get("chrootCmd").(Command)
chrootCmd := func(command string) *exec.Cmd {
return ChrootCommand(mountPath, command)
}

// Create our communicator
comm := &Communicator{
Expand Down
2 changes: 1 addition & 1 deletion builder/amazon/chroot/step_copy_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *StepCopyFiles) Run(state multistep.StateBag) multistep.StepAction {
chrootPath := filepath.Join(mountPath, path)
log.Printf("Copying '%s' to '%s'", path, chrootPath)

cmd := fmt.Sprintf("cp %s %s", chrootPath, path)
cmd := fmt.Sprintf("cp %s %s", path, chrootPath)
if err := wrappedCommand(cmd); err != nil {
err := fmt.Errorf("Error copying file: %s", err)
state.Put("error", err)
Expand Down
6 changes: 0 additions & 6 deletions builder/amazon/chroot/step_mount_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/mitchellh/packer/packer"
"log"
"os"
"os/exec"
"path/filepath"
)

Expand Down Expand Up @@ -57,11 +56,6 @@ func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}

chrootCmd := func(command string) *exec.Cmd {
return ChrootCommand(mountPath, command)
}
state.Put("chrootCmd", Command(chrootCmd))

ui.Say("Mounting the root device...")
stderr := new(bytes.Buffer)
mountCommand := fmt.Sprintf("mount %s %s", device, mountPath)
Expand Down

0 comments on commit 831d5ca

Please sign in to comment.