From b1c863bacdb7bff478621b2eaf802e5eb19ad9c7 Mon Sep 17 00:00:00 2001 From: Akizon77 Date: Tue, 10 Mar 2026 17:56:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20https://github.com/komari-monitor/komari?= =?UTF-8?q?/issues/446=20=E5=8E=BB=E9=87=8D=E5=90=8C=E4=B8=80=E7=89=A9?= =?UTF-8?q?=E7=90=86=E8=AE=BE=E5=A4=87=E7=9A=84=E6=8C=82=E8=BD=BD=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitoring/unit/disk.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/monitoring/unit/disk.go b/monitoring/unit/disk.go index 8fc055f..0a5932d 100644 --- a/monitoring/unit/disk.go +++ b/monitoring/unit/disk.go @@ -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 }