mirror of
https://github.com/samuelncui/yatm.git
synced 2026-11-08 12:26:33 +00:00
Unify file queries and Scan execution, retain indexed Identical results, improve Job and Preview workflows, and verify release packaging.
24 lines
756 B
Go
24 lines
756 B
Go
package fileops
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func sameMount(root, filename string) (bool, error) {
|
|
// Device numbers alone cannot distinguish a bind mount of the same filesystem.
|
|
var rootStat, fileStat unix.Statx_t
|
|
flags := unix.AT_SYMLINK_NOFOLLOW | unix.AT_NO_AUTOMOUNT
|
|
if err := unix.Statx(unix.AT_FDCWD, root, flags, unix.STATX_MNT_ID, &rootStat); err != nil {
|
|
return false, err
|
|
}
|
|
if err := unix.Statx(unix.AT_FDCWD, filename, flags, unix.STATX_MNT_ID, &fileStat); err != nil {
|
|
return false, err
|
|
}
|
|
if rootStat.Mask&unix.STATX_MNT_ID == 0 || fileStat.Mask&unix.STATX_MNT_ID == 0 {
|
|
return false, fmt.Errorf("filesystem operation requires kernel mount identity support")
|
|
}
|
|
return rootStat.Mnt_id == fileStat.Mnt_id, nil
|
|
}
|