From 8a9f778e233a51b1896db80703957ef8f9a9d1c5 Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Thu, 14 Sep 2023 17:14:33 -0500 Subject: [PATCH] Add ability for machine rm -f for WSL When passing the force flag to machine rm, wsl needs to stop the VM if it is running before attempting to remove it. [NO NEW TESTS NEEDED] Signed-off-by: Brent Baude --- pkg/machine/wsl/machine.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go index 163493f60d..05be2b55a8 100644 --- a/pkg/machine/wsl/machine.go +++ b/pkg/machine/wsl/machine.go @@ -1522,7 +1522,12 @@ func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, fun var files []string if v.isRunning() { - return "", nil, fmt.Errorf("running vm %q cannot be destroyed", v.Name) + if !opts.Force { + return "", nil, fmt.Errorf("running vm %q cannot be destroyed", v.Name) + } + if err := v.Stop(v.Name, machine.StopOptions{}); err != nil { + return "", nil, err + } } // Collect all the files that need to be destroyed