@@ -584,23 +584,60 @@ fn dir_unsearchable_unreadable() {
584
584
options. mode ( 0o000 ) ;
585
585
check ! ( tmpdir. create_dir_with( "dir" , & options) ) ;
586
586
587
- // Platforms with `O_PATH` can open a directory with no permissions.
587
+ // Platforms with `O_PATH` can open a directory with no permissions. And
588
+ // somehow FreeBSD can too; see `dir_unsearchable_unreadable_ambient`
589
+ // below confirming this.
588
590
if cfg ! ( any(
589
- target_os = "linux" ,
590
591
target_os = "android" ,
591
- target_os = "redox"
592
+ target_os = "linux" ,
593
+ target_os = "redox" ,
592
594
) ) {
593
- check ! ( tmpdir. open_dir( "dir" ) ) ;
595
+ let dir = check ! ( tmpdir. open_dir( "dir" ) ) ;
596
+ assert ! ( dir. entries( ) . is_err( ) ) ;
597
+ assert ! ( dir. open_dir( "." ) . is_err( ) ) ;
598
+ } else if cfg ! ( target_os = "freebsd" ) {
599
+ let dir = check ! ( tmpdir. open_dir( "dir" ) ) ;
600
+ check ! ( dir. metadata( "." ) ) ;
601
+ check ! ( dir. entries( ) ) ;
602
+ check ! ( dir. open_dir( "." ) ) ;
594
603
} else {
595
604
assert ! ( tmpdir. open_dir( "dir" ) . is_err( ) ) ;
596
605
}
597
606
}
598
607
608
+ /// Like `dir_unsearchable_unreadable`, but uses ambient-authority APIs
609
+ /// to test underlying host functionality.
610
+ #[ cfg( unix) ]
611
+ #[ test]
612
+ fn dir_unsearchable_unreadable_ambient ( ) {
613
+ use std:: { fs:: DirBuilder , os:: unix:: fs:: DirBuilderExt } ;
614
+
615
+ let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
616
+
617
+ let mut options = DirBuilder :: new ( ) ;
618
+ options. mode ( 0o000 ) ;
619
+ check ! ( options. create( dir. path( ) . join( "dir" ) ) ) ;
620
+
621
+ // FreeBSD seems able to open directories with 0o000 permissions.
622
+ if cfg ! ( any(
623
+ target_os = "android" ,
624
+ target_os = "linux" ,
625
+ target_os = "redox" ,
626
+ ) ) {
627
+ assert ! ( std:: fs:: File :: open( dir. path( ) . join( "dir" ) ) . is_err( ) ) ;
628
+ assert ! ( std:: fs:: read_dir( dir. path( ) . join( "dir" ) ) . is_err( ) ) ;
629
+ assert ! ( std:: fs:: File :: open( dir. path( ) . join( "dir/." ) ) . is_err( ) ) ;
630
+ } else if cfg ! ( target_os = "freebsd" ) {
631
+ check ! ( std:: fs:: File :: open( dir. path( ) . join( "dir" ) ) ) ;
632
+ check ! ( std:: fs:: read_dir( dir. path( ) . join( "dir" ) ) ) ;
633
+ check ! ( std:: fs:: File :: open( dir. path( ) . join( "dir/." ) ) ) ;
634
+ }
635
+ }
636
+
599
637
/// This test is the same as `symlink_hard_link` but uses `std::fs`'
600
638
/// ambient API instead of `cap_std`. The purpose of this test is to
601
639
/// confirm fundamentally OS-specific behaviors.
602
640
#[ test]
603
- #[ cfg_attr( any( target_os = "macos" , target_os = "freebsd" ) , ignore) ] // submitted to upstream as https://github.com/rust-lang/rust/pull/78026
604
641
fn symlink_hard_link_ambient ( ) {
605
642
#[ cfg( unix) ]
606
643
use std:: os:: unix:: fs:: symlink;
0 commit comments