Skip to content

Commit

Permalink
Bundle: Add helper function to get bundle name with extension
Browse files Browse the repository at this point in the history
The previous commit introduced a warning when crc setup is used with
its -b option, and when the bundle version does not correspond to the
one hardcoded in crc's Makefile. However, if the bundle is unpacked and
one uses `crc setup -b ~/.crc/cache/crc_libvirt_4.11.1_amd64`, the warning
will also be printed because crc_libvirt_4.11.1_amd64 (without
extention) is different from the expected crc_libvirt_4.11.1_amd64.crcbundle.
While it's questionable if -b should accept a path or not, this has been working until now.

This commit introduces a GetBundleNameWithExtension() helper which will be used to silence incorrect warning.
```
$ crc setup -b ~/.crc/cache/crc_libvirt_4.11.1_amd64
WARN Using crc_libvirt_4.11.1_amd64 bundle, but crc_libvirt_4.11.1_amd64.crcbundle is expected for this release
```
  • Loading branch information
praveenkumar committed Sep 13, 2022
1 parent 46f26c8 commit 1144bfa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/crc/machine/bundle/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ func GetBundleNameWithoutExtension(bundleName string) string {
return strings.TrimSuffix(bundleName, bundleExtension)
}

func GetBundleNameWithExtension(bundleName string) string {
if strings.HasSuffix(bundleName, bundleExtension) {
return bundleName
}
return fmt.Sprintf("%s%s", bundleName, bundleExtension)
}

func GetCustomBundleName(bundleFilename string) string {
re := regexp.MustCompile(`(?:_[0-9]+)*.crcbundle$`)
baseName := re.ReplaceAllLiteralString(bundleFilename, "")
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func ValidateBundlePath(bundlePath string, preset crcpreset.Preset) error {
}

userProvidedBundle := filepath.Base(bundlePath)
userProvidedBundle = bundle.GetBundleNameWithExtension(userProvidedBundle)
if userProvidedBundle != constants.GetDefaultBundle(preset) {
// Should append underscore (_) here, as we don't want crc_libvirt_4.7.15.crcbundle
// to be detected as a custom bundle for crc_libvirt_4.7.1.crcbundle
Expand Down

0 comments on commit 1144bfa

Please sign in to comment.