Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg: move regexp compilation out of loops #2331

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/store/instance_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ func GetWslStatus(instName string) (string, error) {
}

var instState string
wslListColsRegex := regexp.MustCompile(`\s+`)
// wsl --list --verbose may have different headers depending on localization, just split by line
for _, rows := range strings.Split(strings.ReplaceAll(string(out), "\r\n", "\n"), "\n") {
cols := regexp.MustCompile(`\s+`).Split(strings.TrimSpace(rows), -1)
cols := wslListColsRegex.Split(strings.TrimSpace(rows), -1)
nameIdx := 0
// '*' indicates default instance
if cols[0] == "*" {
Expand Down
9 changes: 3 additions & 6 deletions pkg/wsl2/wsl_driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,13 @@ func (l *LimaWslDriver) Validate() error {
}
}

re, err := regexp.Compile(`.*tar\.*`)
if err != nil {
return fmt.Errorf("failed to compile file check regex: %w", err)
}
// TODO: real filetype checks
tarFileRegex := regexp.MustCompile(`.*tar\.*`)
for i, image := range l.Yaml.Images {
if unknown := reflectutil.UnknownNonEmptyFields(image, "File"); len(unknown) > 0 {
logrus.Warnf("Ignoring: vmType %s: images[%d]: %+v", *l.Yaml.VMType, i, unknown)
}
// TODO: real filetype checks
match := re.MatchString(image.Location)
match := tarFileRegex.MatchString(image.Location)
if image.Arch == *l.Yaml.Arch && !match {
return fmt.Errorf("unsupported image type for vmType: %s, tarball root file system required: %q", *l.Yaml.VMType, image.Location)
}
Expand Down
Loading