touch: simplify Unix access error check

This commit is contained in:
Daniel Syauqi authored and Sylvestre Ledru committed 2026-10-08 22:09:09 +02:00
1 parent cb4392c25e
commit ca3e965d68
1 file changed
+5 -8
+5 -8
View File
@@ -457,16 +457,13 @@ fn create_without_truncate(path: &Path) -> std::io::Result<fs::File> {
// GNU reports ordinary access failures as "cannot touch", while -c and -h
// report failures to update timestamps as "setting times of".
#[cfg(unix)]
fn cannot_touch_on_access_error(opts: &Options, error: &Error) -> bool {
if opts.no_create || opts.no_deref || error.kind() != ErrorKind::PermissionDenied {
return false;
}
#[cfg(unix)]
if error.raw_os_error() == Some(libc::EACCES) {
return true;
}
!opts.no_create && !opts.no_deref && error.raw_os_error() == Some(libc::EACCES)
}
#[cfg(not(unix))]
fn cannot_touch_on_access_error(_opts: &Options, _error: &Error) -> bool {
false
}