From af6db0ff2dec9bb3544852b541ab3bd0fd08e1f5 Mon Sep 17 00:00:00 2001 From: Konstantin Toshchev Date: Thu, 18 Oct 2018 16:43:17 +0300 Subject: [PATCH] Deleting floppy images on teardown (#159) --- iso/step_add_floppy.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 + } + + } +}