fallback to origin IsLikelyNotMountPoint to avoid regression

Signed-off-by: j4ckstraw <j4ckstraw@foxmail.com>

fix compile error
This commit is contained in:
j4ckstraw 2023-08-30 09:46:50 +08:00
parent 81ef146e2f
commit 47b1002bab

View File

@ -29,6 +29,7 @@ import (
"path/filepath"
"strconv"
"strings"
"syscall"
"time"
"github.com/moby/sys/mountinfo"
@ -403,12 +404,30 @@ func statx(file string) (unix.Statx_t, error) {
return stat, nil
}
func (mounter *Mounter) isLikelyNotMountPoint(file string) (bool, error) {
stat, err := os.Stat(file)
if err != nil {
return true, err
}
rootStat, err := os.Stat(filepath.Dir(strings.TrimSuffix(file, "/")))
if err != nil {
return true, err
}
// If the directory has a different device as parent, then it is a mountpoint.
if stat.Sys().(*syscall.Stat_t).Dev != rootStat.Sys().(*syscall.Stat_t).Dev {
return false, nil
}
return true, nil
}
// IsLikelyNotMountPoint determines if a directory is not a mountpoint.
// If fast check failed, fall back to slow path. If the path is in fact
// a bind mount from one part of a mount to another it will be detected.
// It also can distinguish between mountpoints and symbolic links.
// It is fast but not necessarily ALWAYS correct. If the path is in fact
// a bind mount from one part of a mount to another it will not be detected.
// It also can not distinguish between mountpoints and symbolic links.
// mkdir /tmp/a /tmp/b; mount --bind /tmp/a /tmp/b; IsLikelyNotMountPoint("/tmp/b")
// will return false. When in fact /tmp/b is a mount point.
// will return true. When in fact /tmp/b is a mount point. If this situation
// is of interest to you, don't use this function...
func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
var stat, rootStat unix.Statx_t
var err error
@ -416,8 +435,11 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
if stat, err = statx(file); err != nil {
if errors.Is(err, errStatxNotSupport) {
// not support statx, go slow path
mnt, mntErr := mounter.IsMountPoint(file)
return !mnt, mntErr
// mnt, mntErr := mounter.IsMountPoint(file)
// return !mnt, mntErr
// fall back to isLikelyNotMountPoint
return mounter.isLikelyNotMountPoint(file)
}
return false, err