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 @@ -47,6 +47,7 @@ impl Dir {
47
47
}
48
48
49
49
#[ inline]
50
+ #[ allow( unused_mut) ]
50
51
fn _read_from ( fd : BorrowedFd < ' _ > ) -> io:: Result < Self > {
51
52
let mut any_errors = false ;
52
53
@@ -58,6 +59,7 @@ impl Dir {
58
59
let flags = fcntl_getfl ( fd) ?;
59
60
let fd_for_dir = match openat ( fd, cstr ! ( "." ) , flags | OFlags :: CLOEXEC , Mode :: empty ( ) ) {
60
61
Ok ( fd) => fd,
62
+ #[ cfg( not( target_os = "wasi" ) ) ]
61
63
Err ( io:: Errno :: NOENT ) => {
62
64
// If "." doesn't exist, it means the directory was removed.
63
65
// We treat that as iterating through a directory with no
@@ -352,6 +354,13 @@ fn dir_iterator_handles_io_errors() {
352
354
core:: mem:: forget ( owned_fd) ;
353
355
}
354
356
357
+ // FreeBSD and macOS seem to read some directory entries before we call
358
+ // `.next()`.
359
+ #[ cfg( any( apple, freebsdlike) ) ]
360
+ {
361
+ dir. rewind ( ) ;
362
+ }
363
+
355
364
assert ! ( matches!( dir. next( ) , Some ( Err ( _) ) ) ) ;
356
365
assert ! ( matches!( dir. next( ) , None ) ) ;
357
366
}
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