Skip to content

Commit 0244381

Browse files
committed
Merge branch 'no-force-no-running' into 'main'
rm: Make `rm -f` work if VM is not running See merge request bootc-org/podman-bootc-cli!56
2 parents 00c4432 + 8a8bb90 commit 0244381

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

cmd/rm.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ func prune(id string) error {
6767

6868
defer bootcVM.CloseConnection()
6969

70+
vmExists, err := bootcVM.Exists()
71+
if err != nil {
72+
return fmt.Errorf("unable to check if VM exists: %v", err)
73+
}
74+
75+
if !vmExists {
76+
logrus.Debugf("VM %s is not running", id)
77+
return nil
78+
}
79+
7080
if force {
7181
err := forceKillVM(bootcVM)
7282
if err != nil {
@@ -107,28 +117,19 @@ func pruneAll() error {
107117
}
108118

109119
func killVM(bootcVM vm.BootcVM) (err error) {
110-
vmExists, err := bootcVM.Exists()
120+
var isRunning bool
121+
isRunning, err = bootcVM.IsRunning()
111122
if err != nil {
112-
return fmt.Errorf("unable to check if VM exists: %v", err)
123+
return fmt.Errorf("unable to check if VM is running: %v", err)
113124
}
114125

115-
if vmExists {
116-
var isRunning bool
117-
isRunning, err = bootcVM.IsRunning()
126+
if isRunning {
127+
return fmt.Errorf("VM is currently running. Stop it first or use the -f flag.")
128+
} else {
129+
err = bootcVM.Delete()
118130
if err != nil {
119-
return fmt.Errorf("unable to check if VM is running: %v", err)
120-
}
121-
122-
if isRunning {
123-
return fmt.Errorf("VM is currently running. Stop it first or use the -f flag.")
124-
} else {
125-
err = bootcVM.Delete()
126-
if err != nil {
127-
return
128-
}
131+
return
129132
}
130-
} else {
131-
logrus.Infof("VM does not exist, nothing to kill")
132133
}
133134

134135
return bootcVM.DeleteFromCache()

0 commit comments

Comments
 (0)