Files
seaweedfs/test/fuse_integration/mounted_unix.go
T
Chris Lu b03372dc88 fuse integration: clean TEST_MOUNT_POINT before the parent-device check
filepath.Dir of a trailing-slash path returns the mount itself, so a mounted TEST_MOUNT_POINT ending in / was refused.
2026-10-22 08:12:24 -07:00

34 lines
777 B
Go

//go:build unix
package fuse
import (
"path/filepath"
"syscall"
)
// deviceID returns the device ID of the filesystem containing path.
func deviceID(path string) (uint64, error) {
var st syscall.Stat_t
if err := syscall.Stat(path, &st); err != nil {
return 0, err
}
return uint64(st.Dev), nil
}
// mountedAt reports whether something is actually mounted at path: a plain
// directory shares its parent's device, a mount point does not. The path is
// cleaned first so a trailing slash does not make Dir return the mount itself.
func mountedAt(path string) bool {
path = filepath.Clean(path)
dev, err := deviceID(path)
if err != nil {
return false
}
parentDev, err := deviceID(filepath.Dir(path))
if err != nil {
return false
}
return dev != parentDev
}