ls: fix flaky test test_ls_io_errors
// spell-checker:ignore (words) READMECAREFULLY birthtime doesntexist oneline somebackup lrwx somefile somegroup somehiddenbackup somehiddenfile
+#[cfg(not(windows))]
+extern crate libc;
+extern crate regex;
+#[cfg(not(windows))]
+extern crate tempfile;
#[cfg(unix)]
extern crate unix_socket;
-use crate::common::util::*;
-extern crate regex;
use self::regex::Regex;
-
+use crate::common::util::*;
#[cfg(all(unix, feature = "chmod"))]
-use nix::unistd::{close, dup2};
+use nix::unistd::{close, dup};
use std::collections::HashMap;
#[cfg(all(unix, feature = "chmod"))]
-use std::os::unix::io::AsRawFd;
+use std::os::unix::io::IntoRawFd;
use std::path::Path;
-use std::thread::sleep;
-use std::time::Duration;
-#[cfg(not(windows))]
-extern crate libc;
#[cfg(not(windows))]
use std::path::PathBuf;
#[cfg(not(windows))]
use std::sync::Mutex;
-#[cfg(not(windows))]
-extern crate tempfile;
+use std::thread::sleep;
+use std::time::Duration;
#[cfg(not(windows))]
lazy_static! {
@@ -142,7 +141,7 @@ fn test_ls_devices() {
}
}
-#[cfg(all(feature = "chmod"))]
+#[cfg(feature = "chmod")]
#[test]
fn test_ls_io_errors() {
let scene = TestScenario::new(util_name!());
@@ -202,14 +201,10 @@ fn test_ls_io_errors() {
#[cfg(unix)]
{
at.touch("some-dir4/bad-fd.txt");
- let fd1 = at.open("some-dir4/bad-fd.txt").as_raw_fd();
- let fd2 = 25000;
- let rv1 = dup2(fd1, fd2);
- let rv2 = close(fd1);
-
- // dup and close work on the mac, but doesn't work in some linux containers
- // so check to see that return values are non-error before proceeding
- if rv1.is_ok() && rv2.is_ok() {
+ let fd1 = at.open("some-dir4/bad-fd.txt").into_raw_fd();
+ let fd2 = dup(dbg!(fd1)).unwrap();
+ close(fd1).unwrap();
+
// on the mac and in certain Linux containers bad fds are typed as dirs,
// however sometimes bad fds are typed as links and directory entry on links won't fail
if PathBuf::from(format!("/dev/fd/{fd}", fd = fd2)).is_dir() {
@@ -251,7 +246,7 @@ fn test_ls_io_errors() {
.arg("-alL")
.arg(format!("/dev/fd/{fd}", fd = fd2))
.succeeds();
- }
+
let _ = close(fd2);
}
}
