|
6 | 6 | /* Last synced with: sync (GNU coreutils) 8.13 */ |
7 | 7 |
|
8 | 8 | use clap::{Arg, ArgAction, Command}; |
9 | | -#[cfg(any(target_os = "linux", target_os = "android"))] |
10 | | -use nix::errno::Errno; |
11 | | -#[cfg(any(target_os = "linux", target_os = "android"))] |
12 | | -use nix::fcntl::{OFlag, open}; |
13 | | -#[cfg(any(target_os = "linux", target_os = "android"))] |
14 | | -use nix::sys::stat::Mode; |
15 | 9 | use std::path::Path; |
16 | 10 | use uucore::display::Quotable; |
17 | 11 | use uucore::error::{UResult, USimpleError, get_exit_code, set_exit_code}; |
@@ -235,13 +229,22 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { |
235 | 229 | #[cfg(any(target_os = "linux", target_os = "android"))] |
236 | 230 | { |
237 | 231 | let path = Path::new(&f); |
238 | | - if let Err(e) = open(path, OFlag::O_NONBLOCK, Mode::empty()) { |
239 | | - if e != Errno::EACCES || (e == Errno::EACCES && path.is_dir()) { |
240 | | - show_error!( |
241 | | - "{}", |
242 | | - translate!("sync-error-opening-file", "file" => f.quote(), "err" => e.desc()) |
243 | | - ); |
244 | | - set_exit_code(1); |
| 232 | + match rustix::fs::open( |
| 233 | + path, |
| 234 | + rustix::fs::OFlags::NONBLOCK, |
| 235 | + rustix::fs::Mode::empty(), |
| 236 | + ) { |
| 237 | + Ok(_fd) => { /* OwnedFd auto-closes on drop */ } |
| 238 | + Err(e) => { |
| 239 | + let is_eacces = e == rustix::io::Errno::ACCESS; |
| 240 | + if !is_eacces || path.is_dir() { |
| 241 | + let err = std::io::Error::from(e); |
| 242 | + show_error!( |
| 243 | + "{}", |
| 244 | + translate!("sync-error-opening-file", "file" => f.quote(), "err" => err) |
| 245 | + ); |
| 246 | + set_exit_code(1); |
| 247 | + } |
245 | 248 | } |
246 | 249 | } |
247 | 250 | } |
|
0 commit comments