Skip to content

Commit

Permalink
Merge pull request #2674 from AkihiroSuda/factory-reset-keep-lima-ver…
Browse files Browse the repository at this point in the history
…sion

limactl factory-reset: keep "lima-version" and "protected"
  • Loading branch information
AkihiroSuda authored Oct 2, 2024
2 parents cc85e16 + a6033ef commit 16fd466
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/limactl/factory-reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,24 @@ func factoryResetAction(_ *cobra.Command, args []string) error {
}
return err
}
if inst.Protected {
return errors.New("instance is protected to prohibit accidental factory-reset (Hint: use `limactl unprotect`)")
}

instance.StopForcibly(inst)

fi, err := os.ReadDir(inst.Dir)
if err != nil {
return err
}
retain := map[string]struct{}{
filenames.LimaVersion: {},
filenames.Protected: {},
filenames.VzIdentifier: {},
}
for _, f := range fi {
path := filepath.Join(inst.Dir, f.Name())
if !strings.HasSuffix(path, ".yaml") && !strings.HasSuffix(path, ".yml") && f.Name() != filenames.VzIdentifier {
if _, ok := retain[f.Name()]; !ok && !strings.HasSuffix(path, ".yaml") && !strings.HasSuffix(path, ".yml") {
logrus.Infof("Removing %q", path)
if err := os.Remove(path); err != nil {
logrus.Error(err)
Expand Down

0 comments on commit 16fd466

Please sign in to comment.