@@ -404,7 +404,7 @@ func statx(file string) (unix.Statx_t, error) {
404
404
return stat , nil
405
405
}
406
406
407
- func (mounter * Mounter ) isLikelyNotMountPoint (file string ) (bool , error ) {
407
+ func (mounter * Mounter ) isLikelyNotMountPointStat (file string ) (bool , error ) {
408
408
stat , err := os .Stat (file )
409
409
if err != nil {
410
410
return true , err
@@ -421,27 +421,11 @@ func (mounter *Mounter) isLikelyNotMountPoint(file string) (bool, error) {
421
421
return true , nil
422
422
}
423
423
424
- // IsLikelyNotMountPoint determines if a directory is not a mountpoint.
425
- // It is fast but not necessarily ALWAYS correct. If the path is in fact
426
- // a bind mount from one part of a mount to another it will not be detected.
427
- // It also can not distinguish between mountpoints and symbolic links.
428
- // mkdir /tmp/a /tmp/b; mount --bind /tmp/a /tmp/b; IsLikelyNotMountPoint("/tmp/b")
429
- // will return true. When in fact /tmp/b is a mount point. If this situation
430
- // is of interest to you, don't use this function...
431
- func (mounter * Mounter ) IsLikelyNotMountPoint (file string ) (bool , error ) {
424
+ func (mounter * Mounter ) isLikelyNotMountPointStatx (file string ) (bool , error ) {
432
425
var stat , rootStat unix.Statx_t
433
426
var err error
434
427
435
428
if stat , err = statx (file ); err != nil {
436
- if errors .Is (err , errStatxNotSupport ) {
437
- // not support statx, go slow path
438
- // mnt, mntErr := mounter.IsMountPoint(file)
439
- // return !mnt, mntErr
440
-
441
- // fall back to isLikelyNotMountPoint
442
- return mounter .isLikelyNotMountPoint (file )
443
- }
444
-
445
429
return true , err
446
430
}
447
431
@@ -465,6 +449,23 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
465
449
return (stat .Dev_major == rootStat .Dev_major && stat .Dev_minor == rootStat .Dev_minor ), nil
466
450
}
467
451
452
+ // IsLikelyNotMountPoint determines if a directory is not a mountpoint.
453
+ // It is fast but not necessarily ALWAYS correct. If the path is in fact
454
+ // a bind mount from one part of a mount to another it will not be detected.
455
+ // It also can not distinguish between mountpoints and symbolic links.
456
+ // mkdir /tmp/a /tmp/b; mount --bind /tmp/a /tmp/b; IsLikelyNotMountPoint("/tmp/b")
457
+ // will return true. When in fact /tmp/b is a mount point. If this situation
458
+ // is of interest to you, don't use this function...
459
+ func (mounter * Mounter ) IsLikelyNotMountPoint (file string ) (bool , error ) {
460
+ notMountPoint , err := mounter .isLikelyNotMountPointStatx (file )
461
+ if errors .Is (err , errStatxNotSupport ) {
462
+ // fall back to isLikelyNotMountPointStat
463
+ return mounter .isLikelyNotMountPointStat (file )
464
+ }
465
+
466
+ return notMountPoint , err
467
+ }
468
+
468
469
// CanSafelySkipMountPointCheck relies on the detected behavior of umount when given a target that is not a mount point.
469
470
func (mounter * Mounter ) CanSafelySkipMountPointCheck () bool {
470
471
return mounter .withSafeNotMountedBehavior
0 commit comments