machine: qemu only remove connection after confirmation

the connection remove call must be done inside the function that is
returned so that we wait until the user confirmed it.

Fixes #18330

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2023-04-26 16:44:28 +02:00
parent 846e7aa21b
commit 2296e71e39

View File

@ -964,13 +964,6 @@ func (v *MachineVM) Remove(_ string, opts machine.RemoveOptions) (string, func()
files = append(files, socketPath.Path)
files = append(files, v.archRemovalFiles()...)
if err := machine.RemoveConnection(v.Name); err != nil {
logrus.Error(err)
}
if err := machine.RemoveConnection(v.Name + "-root"); err != nil {
logrus.Error(err)
}
vmConfigDir, err := machine.GetConfDir(vmtype)
if err != nil {
return "", nil, err
@ -1001,6 +994,12 @@ func (v *MachineVM) Remove(_ string, opts machine.RemoveOptions) (string, func()
logrus.Error(err)
}
}
if err := machine.RemoveConnection(v.Name); err != nil {
logrus.Error(err)
}
if err := machine.RemoveConnection(v.Name + "-root"); err != nil {
logrus.Error(err)
}
return nil
}, nil
}