Skip to content

Commit

Permalink
logical_disk: revert panic trigger on error (#1755)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke authored Nov 22, 2024
1 parent 4534c2a commit a602d7b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/collector/logical_disk/logical_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,17 @@ func getVolumeInfo(rootDrive string) (volumeInfo, error) {

// If rootDrive is a NTFS directory, convert it to a volume GUID.
if strings.Contains(volumePath, `\`) {
volumePathName, err := windows.UTF16PtrFromString(volumePath + `\`)
// GetVolumeNameForVolumeMountPoint expects a trailing backslash.
volumePath += `\`

volumePathName, err := windows.UTF16PtrFromString(volumePath)
if err != nil {
return volumeInfo{}, fmt.Errorf("could not convert rootDrive to volume path: %w", err)
return volumeInfo{}, fmt.Errorf("could not convert rootDrive to volume path %s: %w", volumePath, err)
}

volumeGUIDPtr := make([]uint16, 50)
if err := windows.GetVolumeNameForVolumeMountPoint(volumePathName, &volumeGUIDPtr[0], uint32(len(volumeGUIDPtr))); err != nil {
panic(fmt.Errorf("could not get volume GUID: %w", err))
return volumeInfo{}, fmt.Errorf("could not get volume GUID for volume %s: %w", volumePath, err)
}

volumePath = windows.UTF16ToString(volumeGUIDPtr)
Expand Down

0 comments on commit a602d7b

Please sign in to comment.