File tree 2 files changed +14
-0
lines changed 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ impl Dir {
46
46
}
47
47
48
48
#[ inline]
49
+ #[ allow( unused_mut) ]
49
50
fn _read_from ( fd : BorrowedFd < ' _ > ) -> io:: Result < Self > {
50
51
let mut any_errors = false ;
51
52
@@ -57,6 +58,7 @@ impl Dir {
57
58
let flags = fcntl_getfl ( fd) ?;
58
59
let fd_for_dir = match openat ( fd, cstr ! ( "." ) , flags | OFlags :: CLOEXEC , Mode :: empty ( ) ) {
59
60
Ok ( fd) => fd,
61
+ #[ cfg( not( target_os = "wasi" ) ) ]
60
62
Err ( io:: Errno :: NOENT ) => {
61
63
// If "." doesn't exist, it means the directory was removed.
62
64
// We treat that as iterating through a directory with no
@@ -341,6 +343,13 @@ fn dir_iterator_handles_io_errors() {
341
343
core:: mem:: forget ( owned_fd) ;
342
344
}
343
345
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
+
344
353
assert ! ( matches!( dir. next( ) , Some ( Err ( _) ) ) ) ;
345
354
assert ! ( matches!( dir. next( ) , None ) ) ;
346
355
}
Original file line number Diff line number Diff line change @@ -62,6 +62,10 @@ fn test_dir() {
62
62
assert ! ( saw_cargo_toml) ;
63
63
}
64
64
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) ]
65
69
#[ test]
66
70
fn dir_iterator_handles_dir_removal ( ) {
67
71
// create a dir, keep the FD, then delete the dir
@@ -83,6 +87,7 @@ fn dir_iterator_handles_dir_removal() {
83
87
84
88
// Like `dir_iterator_handles_dir_removal`, but close the directory after
85
89
// `Dir::read_from`.
90
+ #[ cfg_attr( any( apple, freebsdlike) , ignore) ]
86
91
#[ test]
87
92
fn dir_iterator_handles_dir_removal_after_open ( ) {
88
93
// create a dir, keep the FD, then delete the dir
You can’t perform that action at this time.
0 commit comments