builder/amazon/chroot: unmount in reverse

This commit is contained in:
Mitchell Hashimoto 2013-07-30 13:21:25 -07:00
parent 9dc55ee56c
commit 778657e995
1 changed files with 6 additions and 2 deletions

View File

@ -72,12 +72,16 @@ func (s *StepMountExtra) Cleanup(state map[string]interface{}) {
config := state["config"].(*Config)
ui := state["ui"].(packer.Ui)
for _, path := range s.mounts {
for i := len(s.mounts) - 1; i >= 0; i-- {
path := s.mounts[i]
unmountCommand := fmt.Sprintf("%s %s", config.UnmountCommand, path)
stderr := new(bytes.Buffer)
cmd := exec.Command("/bin/sh", "-c", unmountCommand)
cmd.Stderr = stderr
if err := cmd.Run(); err != nil {
ui.Error(fmt.Sprintf(
"Error unmounting root device: %s", err))
"Error unmounting device: %s\nStderr: %s", err, stderr.String()))
return
}
}