(ctx context.Context, inst *limatype.Instance, force bool)
| 14 | ) |
| 15 | |
| 16 | func Delete(ctx context.Context, inst *limatype.Instance, force bool) error { |
| 17 | if inst.Protected { |
| 18 | return errors.New("instance is protected to prohibit accidental removal (Hint: use `limactl unprotect`)") |
| 19 | } |
| 20 | if !force && inst.Status != limatype.StatusStopped { |
| 21 | return fmt.Errorf("expected status %q, got %q", limatype.StatusStopped, inst.Status) |
| 22 | } |
| 23 | |
| 24 | StopForcibly(inst) |
| 25 | |
| 26 | if len(inst.Errors) == 0 { |
| 27 | if err := unregister(ctx, inst); err != nil { |
| 28 | return fmt.Errorf("failed to unregister %q: %w", inst.Dir, err) |
| 29 | } |
| 30 | } |
| 31 | if err := os.RemoveAll(inst.Dir); err != nil { |
| 32 | return fmt.Errorf("failed to remove %q: %w", inst.Dir, err) |
| 33 | } |
| 34 | |
| 35 | return nil |
| 36 | } |
| 37 | |
| 38 | func unregister(ctx context.Context, inst *limatype.Instance) error { |
| 39 | limaDriver, err := driverutil.CreateConfiguredDriver(ctx, inst, 0, "") |
no test coverage detected