mirror of
https://github.com/fankes/komari-agent.git
synced 2026-03-26 21:35:12 +08:00
fix: https://github.com/komari-monitor/komari/issues/446 去重同一物理设备的挂载点
This commit is contained in:
@@ -171,11 +171,33 @@ func DiskList() ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 同一物理设备只保留路径最短的根挂载点
|
||||
deviceMap := make(map[string]disk.PartitionStat)
|
||||
for _, part := range usage {
|
||||
if isPhysicalDisk(part) {
|
||||
diskList = append(diskList, fmt.Sprintf("%s (%s)", part.Mountpoint, part.Fstype))
|
||||
deviceID := part.Device
|
||||
// ZFS去重: 基于 pool 名称
|
||||
if strings.ToLower(part.Fstype) == "zfs" {
|
||||
if idx := strings.Index(deviceID, "/"); idx != -1 {
|
||||
deviceID = deviceID[:idx]
|
||||
}
|
||||
}
|
||||
|
||||
if existing, ok := deviceMap[deviceID]; ok {
|
||||
// 优先保留路径更短的挂载点 (e.g., /volume1 优于 /volume1/@appdata/...)
|
||||
if len(part.Mountpoint) < len(existing.Mountpoint) {
|
||||
deviceMap[deviceID] = part
|
||||
}
|
||||
} else {
|
||||
deviceMap[deviceID] = part
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, part := range deviceMap {
|
||||
diskList = append(diskList, fmt.Sprintf("%s (%s)", part.Mountpoint, part.Fstype))
|
||||
}
|
||||
}
|
||||
return diskList, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user