diff --git a/iso/step_add_floppy.go b/iso/step_add_floppy.go index f03511452..46974a087 100644 --- a/iso/step_add_floppy.go +++ b/iso/step_add_floppy.go @@ -67,4 +67,30 @@ func (s *StepAddFloppy) Run(_ context.Context, state multistep.StateBag) multist return multistep.ActionContinue } -func (s *StepAddFloppy) Cleanup(state multistep.StateBag) {} +func (s *StepAddFloppy) Cleanup(state multistep.StateBag) { + _, cancelled := state.GetOk(multistep.StateCancelled) + _, halted := state.GetOk(multistep.StateHalted) + if !cancelled && !halted { + return + } + + ui := state.Get("ui").(packer.Ui) + d := state.Get("driver").(*driver.Driver) + + if UploadedFloppyPath, ok := state.GetOk("uploaded_floppy_path"); ok { + ui.Say("Deleting Floppy image ...") + + ds, err := d.FindDatastore(s.Datastore, s.Host) + if err != nil { + state.Put("error", err) + return + } + + err_del := ds.Delete(UploadedFloppyPath.(string)) + if err_del != nil { + state.Put("error", err) + return + } + + } +}