Fix empty disk mount detection
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user