Skip to content

Commit

Permalink
Merge pull request #6601 from mook-as/win32/installer/wsl-msi-version…
Browse files Browse the repository at this point in the history
…-no-buffer

WSL-Helper: Fix getting MSI version
  • Loading branch information
jandubois committed Mar 12, 2024
2 parents d4097c8 + 1c334e8 commit 92abdb1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/go/wsl-helper/pkg/wsl-utils/version_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (i WSLInfo) String() string {
if len(parts) == 0 {
parts = append(parts, "not-installed")
}
return fmt.Sprintf("Version=%s (%s)", i.Version, strings.Join(parts, ", "))
return fmt.Sprintf("Version=%s kernel=%s (%s)", i.Version, i.KernelVersion, strings.Join(parts, ", "))
}

const (
Expand Down Expand Up @@ -403,7 +403,7 @@ func getInboxWSLInfo(ctx context.Context, log *logrus.Entry) (bool, *PackageVers
)
switch rv {
case uintptr(windows.ERROR_SUCCESS):
kernelVersion, err = getMSIVersion(productCode)
kernelVersion, err = getMSIVersion(productCode, log)
if err != nil {
allErrors = append(allErrors, fmt.Errorf("error getting kernel version: %w", err))
}
Expand All @@ -419,7 +419,7 @@ func getInboxWSLInfo(ctx context.Context, log *logrus.Entry) (bool, *PackageVers
}

// Get the version of an installed MSI package, given its product code.
func getMSIVersion(productCode []uint16) (*PackageVersion, error) {
func getMSIVersion(productCode []uint16, log *logrus.Entry) (*PackageVersion, error) {
version := PackageVersion{}
versionStringWide, err := windows.UTF16PtrFromString(INSTALLPROPERTY_VERSIONSTRING)
if err != nil {
Expand All @@ -436,7 +436,8 @@ func getMSIVersion(productCode []uint16) (*PackageVersion, error) {
)
switch rv {
case uintptr(windows.ERROR_SUCCESS):
return nil, fmt.Errorf("succeeded getting product version with no buffer")
log.WithFields(logrus.Fields{"bufSize": bufSize}).Trace("unexpected success, assuming needs more data")
fallthrough
case uintptr(windows.ERROR_MORE_DATA):
wideBuf = make([]uint16, bufSize+1) // Add space for null terminator
bufSize = len(wideBuf)
Expand Down

0 comments on commit 92abdb1

Please sign in to comment.