Skip to content

Commit 0736521

Browse files
committed
fix: 修复macos识别问题
1 parent 8ec5d73 commit 0736521

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

system/disk.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -354,27 +354,26 @@ func getFallbackDiskInfo() *DiskSingelInfo {
354354
}
355355

356356
func consolidateDiskInfos(diskInfos []DiskSingelInfo, currentDiskInfo *DiskSingelInfo) []DiskSingelInfo {
357-
var finalDiskInfos []DiskSingelInfo
358-
if len(diskInfos) == 0 {
359-
if currentDiskInfo != nil {
360-
finalDiskInfos = append(finalDiskInfos, *currentDiskInfo)
357+
diskMap := make(map[string]DiskSingelInfo)
358+
for _, info := range diskInfos {
359+
physicalName := getPhysicalDiskName(info.BootPath)
360+
existing, ok := diskMap[physicalName]
361+
if !ok || info.TotalBytes > existing.TotalBytes {
362+
diskMap[physicalName] = info
361363
}
362-
} else {
363-
finalDiskInfos = diskInfos
364-
if currentDiskInfo != nil {
365-
currentInList := false
366-
for _, info := range diskInfos {
367-
if info.BootPath == currentDiskInfo.BootPath {
368-
currentInList = true
369-
break
370-
}
371-
}
372-
if !currentInList {
373-
finalDiskInfos = append(finalDiskInfos, *currentDiskInfo)
374-
}
364+
}
365+
if currentDiskInfo != nil {
366+
physName := getPhysicalDiskName(currentDiskInfo.BootPath)
367+
_, exists := diskMap[physName]
368+
if !exists {
369+
diskMap[physName] = *currentDiskInfo
375370
}
376371
}
377-
return finalDiskInfos
372+
var result []DiskSingelInfo
373+
for _, v := range diskMap {
374+
result = append(result, v)
375+
}
376+
return result
378377
}
379378

380379
func createDiskInfo(totalBytes, usedBytes uint64, bootPath, mountPath string) DiskSingelInfo {

0 commit comments

Comments
 (0)