File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ impl Dir {
4646 }
4747
4848 #[ inline]
49+ #[ allow( unused_mut) ]
4950 fn _read_from ( fd : BorrowedFd < ' _ > ) -> io:: Result < Self > {
5051 let mut any_errors = false ;
5152
@@ -57,6 +58,7 @@ impl Dir {
5758 let flags = fcntl_getfl ( fd) ?;
5859 let fd_for_dir = match openat ( fd, cstr ! ( "." ) , flags | OFlags :: CLOEXEC , Mode :: empty ( ) ) {
5960 Ok ( fd) => fd,
61+ #[ cfg( not( target_os = "wasi" ) ) ]
6062 Err ( io:: Errno :: NOENT ) => {
6163 // If "." doesn't exist, it means the directory was removed.
6264 // We treat that as iterating through a directory with no
@@ -341,6 +343,13 @@ fn dir_iterator_handles_io_errors() {
341343 core:: mem:: forget ( owned_fd) ;
342344 }
343345
346+ // FreeBSD and macOS seem to read some directory entries before we call
347+ // `.next()`.
348+ #[ cfg( any( apple, freebsdlike) ) ]
349+ {
350+ dir. rewind ( ) ;
351+ }
352+
344353 assert ! ( matches!( dir. next( ) , Some ( Err ( _) ) ) ) ;
345354 assert ! ( matches!( dir. next( ) , None ) ) ;
346355}
Original file line number Diff line number Diff line change @@ -62,6 +62,10 @@ fn test_dir() {
6262 assert ! ( saw_cargo_toml) ;
6363}
6464
65+ // Test that `Dir` silently stops iterating if the directory has been removed.
66+ //
67+ // Except on FreeBSD and macOS, where apparently `readdir` just keeps reading.
68+ #[ cfg_attr( any( apple, freebsdlike) , ignore) ]
6569#[ test]
6670fn dir_iterator_handles_dir_removal ( ) {
6771 // create a dir, keep the FD, then delete the dir
@@ -83,6 +87,7 @@ fn dir_iterator_handles_dir_removal() {
8387
8488// Like `dir_iterator_handles_dir_removal`, but close the directory after
8589// `Dir::read_from`.
90+ #[ cfg_attr( any( apple, freebsdlike) , ignore) ]
8691#[ test]
8792fn dir_iterator_handles_dir_removal_after_open ( ) {
8893 // create a dir, keep the FD, then delete the dir
You can’t perform that action at this time.
0 commit comments