Skip to content

Commit 92abdb1

Browse files
authored
Merge pull request #6601 from mook-as/win32/installer/wsl-msi-version-no-buffer
WSL-Helper: Fix getting MSI version
2 parents d4097c8 + 1c334e8 commit 92abdb1

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/go/wsl-helper/pkg/wsl-utils/version_windows.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (i WSLInfo) String() string {
5959
if len(parts) == 0 {
6060
parts = append(parts, "not-installed")
6161
}
62-
return fmt.Sprintf("Version=%s (%s)", i.Version, strings.Join(parts, ", "))
62+
return fmt.Sprintf("Version=%s kernel=%s (%s)", i.Version, i.KernelVersion, strings.Join(parts, ", "))
6363
}
6464

6565
const (
@@ -403,7 +403,7 @@ func getInboxWSLInfo(ctx context.Context, log *logrus.Entry) (bool, *PackageVers
403403
)
404404
switch rv {
405405
case uintptr(windows.ERROR_SUCCESS):
406-
kernelVersion, err = getMSIVersion(productCode)
406+
kernelVersion, err = getMSIVersion(productCode, log)
407407
if err != nil {
408408
allErrors = append(allErrors, fmt.Errorf("error getting kernel version: %w", err))
409409
}
@@ -419,7 +419,7 @@ func getInboxWSLInfo(ctx context.Context, log *logrus.Entry) (bool, *PackageVers
419419
}
420420

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

0 commit comments

Comments
 (0)