diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 08ba6b1d4..0fa81218a 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -11,6 +11,8 @@ extern crate libc; use clap::{crate_version, Arg, ArgAction, Command}; #[cfg(any(target_os = "linux", target_os = "android"))] +use nix::errno::Errno; +#[cfg(any(target_os = "linux", target_os = "android"))] use nix::fcntl::{open, OFlag}; #[cfg(any(target_os = "linux", target_os = "android"))] use nix::sys::stat::Mode; @@ -170,9 +172,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // Use the Nix open to be able to set the NONBLOCK flags for fifo files #[cfg(any(target_os = "linux", target_os = "android"))] { - open(Path::new(&f), OFlag::O_NONBLOCK, Mode::empty()) - .map_err_context(|| format!("cannot stat {}", f.quote()))?; + let path = Path::new(&f); + if let Err(e) = open(path, OFlag::O_NONBLOCK, Mode::empty()) { + if e != Errno::EACCES || (e == Errno::EACCES && path.is_dir()) { + return e.map_err_context(|| format!("cannot stat {}", f.quote()))?; + } + } } + #[cfg(not(any(target_os = "linux", target_os = "android")))] { if !Path::new(&f).exists() { diff --git a/tests/by-util/test_sync.rs b/tests/by-util/test_sync.rs index 7f2cd4b66..4bf2629c4 100644 --- a/tests/by-util/test_sync.rs +++ b/tests/by-util/test_sync.rs @@ -64,9 +64,9 @@ fn test_sync_no_permission_dir() { ts.ccmd("chmod").arg("0").arg(dir).succeeds(); let result = ts.ucmd().arg("--data").arg(dir).fails(); - result.stderr_contains("sync: error opening 'foo': Permission denied"); + result.stderr_contains("sync: cannot stat 'foo': Permission denied"); let result = ts.ucmd().arg(dir).fails(); - result.stderr_contains("sync: error opening 'foo': Permission denied"); + result.stderr_contains("sync: cannot stat 'foo': Permission denied"); } #[cfg(not(target_os = "windows"))]