Skip to content

Commit

Permalink
parallels: simplify regex for vm files
Browse files Browse the repository at this point in the history
The original regex had multiple occurrences of a `.+?' pattern, which is
essentially the same as a `.*', so we replace the former by the latter
for clarity.

Additionally, since the beginning of the path does not interest us, we
can ignore it from the regex, and only start matching once we have found
what's interesting for us, further simplifying the expression.
  • Loading branch information
lbajolet-hashicorp authored and nywilken committed Jan 16, 2024
1 parent d22623a commit 308d101
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions post-processor/vagrant/parallels.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func (p *ParallelsProvider) Process(ui packersdk.Ui, artifact packersdk.Artifact
}

tmpPath := filepath.ToSlash(path)
pathRe := regexp.MustCompile(`^(.+?)([^/]+\.(pvm|macvm)/.+?)$`)
matches := pathRe.FindStringSubmatch(tmpPath)
pathRe := regexp.MustCompile(`[^/]+\.(pvm|macvm)/.+$`)
match := pathRe.FindString(tmpPath)
var pvmPath string
if matches != nil {
pvmPath = filepath.FromSlash(matches[2])
if match != "" {
pvmPath = filepath.FromSlash(match)
} else {
continue // Just copy a pvm
}
Expand Down

0 comments on commit 308d101

Please sign in to comment.