Skip to content

Commit 16fd466

Browse files
authored
Merge pull request #2674 from AkihiroSuda/factory-reset-keep-lima-version
limactl factory-reset: keep "lima-version" and "protected"
2 parents cc85e16 + a6033ef commit 16fd466

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cmd/limactl/factory-reset.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,24 @@ func factoryResetAction(_ *cobra.Command, args []string) error {
3939
}
4040
return err
4141
}
42+
if inst.Protected {
43+
return errors.New("instance is protected to prohibit accidental factory-reset (Hint: use `limactl unprotect`)")
44+
}
4245

4346
instance.StopForcibly(inst)
4447

4548
fi, err := os.ReadDir(inst.Dir)
4649
if err != nil {
4750
return err
4851
}
52+
retain := map[string]struct{}{
53+
filenames.LimaVersion: {},
54+
filenames.Protected: {},
55+
filenames.VzIdentifier: {},
56+
}
4957
for _, f := range fi {
5058
path := filepath.Join(inst.Dir, f.Name())
51-
if !strings.HasSuffix(path, ".yaml") && !strings.HasSuffix(path, ".yml") && f.Name() != filenames.VzIdentifier {
59+
if _, ok := retain[f.Name()]; !ok && !strings.HasSuffix(path, ".yaml") && !strings.HasSuffix(path, ".yml") {
5260
logrus.Infof("Removing %q", path)
5361
if err := os.Remove(path); err != nil {
5462
logrus.Error(err)

0 commit comments

Comments
 (0)