Skip to content

Commit 771dde1

Browse files
committed
adding excludedDirs
Signed-off-by: Songpon Srisawai <[email protected]>
1 parent e5b4e3a commit 771dde1

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

pkg/limayaml/validate.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ func Validate(y *LimaYAML, warn bool) error {
145145
}
146146

147147
var mountErrs []error
148+
excludedDirs := []string{"/tmp/lima"}
149+
148150
for i, f := range y.Mounts {
149151
if !filepath.IsAbs(f.Location) && !strings.HasPrefix(f.Location, "~") {
150152
mountErrs = append(mountErrs, fmt.Errorf("field `mounts[%d].location` must be an absolute path, got %q", i, f.Location))
@@ -154,15 +156,17 @@ func Validate(y *LimaYAML, warn bool) error {
154156
if err != nil {
155157
mountErrs = append(mountErrs, fmt.Errorf("field `mounts[%d].location` refers to an unexpandable path: %q: %w", i, f.Location, err))
156158
}
157-
st, err := os.Stat(loc)
158-
if err != nil {
159-
if errors.Is(err, os.ErrNotExist) {
160-
mountErrs = append(mountErrs, fmt.Errorf("field `mounts[%d].location` refers to non-existent path: %q: %w", i, f.Location, err))
161-
continue
159+
if !isContain(loc, excludedDirs) {
160+
st, err := os.Stat(loc)
161+
if err != nil {
162+
if errors.Is(err, os.ErrNotExist) {
163+
mountErrs = append(mountErrs, fmt.Errorf("field `mounts[%d].location` refers to non-existent path: %q: %w", i, f.Location, err))
164+
} else {
165+
mountErrs = append(mountErrs, fmt.Errorf("field `mounts[%d].location` refers to an inaccessible path: %q: %w", i, f.Location, err))
166+
}
167+
} else if !st.IsDir() {
168+
mountErrs = append(mountErrs, fmt.Errorf("field `mounts[%d].location` refers to a non-directory path: %q: %w", i, f.Location, err))
162169
}
163-
mountErrs = append(mountErrs, fmt.Errorf("field `mounts[%d].location` refers to an inaccessible path: %q: %w", i, f.Location, err))
164-
} else if !st.IsDir() {
165-
mountErrs = append(mountErrs, fmt.Errorf("field `mounts[%d].location` refers to a non-directory path: %q: %w", i, f.Location, err))
166170
}
167171

168172
switch *f.MountPoint {
@@ -601,3 +605,12 @@ func warnExperimental(y *LimaYAML) {
601605
logrus.Warn("`mountInotify` is experimental")
602606
}
603607
}
608+
609+
func isContain(v string, slice []string) bool {
610+
for _, s := range slice {
611+
if s == v {
612+
return true
613+
}
614+
}
615+
return false
616+
}

0 commit comments

Comments
 (0)