@@ -1701,6 +1701,13 @@ pub fn link(original: &Path, link: &Path) -> io::Result<()> {
1701
1701
} )
1702
1702
}
1703
1703
1704
+ // On linux this is the default behavior for lstat and stat but it has to be set explicitly for fstatat
1705
+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
1706
+ const DEFAULT_STATAT_FLAGS : c_int = libc:: AT_NO_AUTOMOUNT ;
1707
+
1708
+ #[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
1709
+ const DEFAULT_STATAT_FLAGS : c_int = 0 ;
1710
+
1704
1711
pub fn stat ( path : & Path ) -> io:: Result < FileAttr > {
1705
1712
run_path_with_cstr ( path, |p| {
1706
1713
cfg_has_statx ! {
@@ -1716,7 +1723,12 @@ pub fn stat(path: &Path) -> io::Result<FileAttr> {
1716
1723
}
1717
1724
1718
1725
let mut stat: stat64 = unsafe { mem:: zeroed ( ) } ;
1719
- cvt ( unsafe { stat64 ( p. as_ptr ( ) , & mut stat) } ) ?;
1726
+ let result = cvt ( unsafe { stat64 ( p. as_ptr ( ) , & mut stat) } ) ;
1727
+ long_filename_fallback ! ( path, result, |dirfd, file_name| {
1728
+ cvt( unsafe {
1729
+ fstatat64( dirfd. as_raw_fd( ) , file_name. as_ptr( ) , & mut stat, DEFAULT_STATAT_FLAGS )
1730
+ } )
1731
+ } ) ?;
1720
1732
Ok ( FileAttr :: from_stat64 ( stat) )
1721
1733
} )
1722
1734
}
@@ -1743,7 +1755,7 @@ pub fn lstat(path: &Path) -> io::Result<FileAttr> {
1743
1755
dirfd. as_raw_fd( ) ,
1744
1756
file_name. as_ptr( ) ,
1745
1757
& mut stat,
1746
- libc:: AT_SYMLINK_NOFOLLOW ,
1758
+ DEFAULT_STATAT_FLAGS | libc:: AT_SYMLINK_NOFOLLOW ,
1747
1759
)
1748
1760
} )
1749
1761
} ) ?;
0 commit comments