Fix empty disk mount detection

This commit is contained in:
2026-04-23 22:58:07 +03:00
parent e7917b41b5
commit 0afc1d761b
2 changed files with 13 additions and 5 deletions

View File

@@ -32,8 +32,7 @@ const idFile = "disk.id"
func Probe(mountPath string) (DiskInfo, error) { func Probe(mountPath string) (DiskInfo, error) {
info := DiskInfo{MountPath: mountPath, State: DiskAbsent} info := DiskInfo{MountPath: mountPath, State: DiskAbsent}
entries, err := os.ReadDir(mountPath) if _, err := os.ReadDir(mountPath); err != nil {
if err != nil || len(entries) == 0 {
return info, nil return info, nil
} }

View File

@@ -5,6 +5,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
"strings"
"sync" "sync"
"time" "time"
@@ -122,14 +123,15 @@ func (w *Watcher) probe() {
} }
func discoverDisks(root string) map[string]disk.DiskInfo { func discoverDisks(root string) map[string]disk.DiskInfo {
disks := make(map[string]disk.DiskInfo)
entries, err := os.ReadDir(root) entries, err := os.ReadDir(root)
if err != nil { if err != nil {
return map[string]disk.DiskInfo{} return disks
} }
disks := make(map[string]disk.DiskInfo)
for _, entry := range entries { for _, entry := range entries {
if !entry.IsDir() { if !entry.IsDir() || strings.HasPrefix(entry.Name(), ".") {
continue continue
} }
mountPath := filepath.Join(root, entry.Name()) mountPath := filepath.Join(root, entry.Name())
@@ -139,5 +141,12 @@ func discoverDisks(root string) map[string]disk.DiskInfo {
} }
disks[mountPath] = info disks[mountPath] = info
} }
// If no child mountpoints were detected, the disk may be mounted directly at root.
if len(disks) == 0 {
if info, _ := disk.Probe(root); info.State != disk.DiskAbsent {
disks[root] = info
}
}
return disks return disks
} }