diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index e27dbfc18..f58d9e6d8 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -83,8 +83,18 @@ Try 'touch --help' for more information."##, for filename in files { let path = Path::new(filename); if !path.exists() { - // no-dereference included here for compatibility - if matches.is_present(options::NO_CREATE) || matches.is_present(options::NO_DEREF) { + if matches.is_present(options::NO_CREATE) { + continue; + } + + if matches.is_present(options::NO_DEREF) { + show!(USimpleError::new( + 1, + format!( + "setting times of {}: No such file or directory", + filename.quote() + ) + )); continue; } diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index dd4a0b6cc..ac82a81ea 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -539,3 +539,16 @@ fn test_touch_no_args() { Try 'touch --help' for more information."##, ); } + +#[test] +fn test_no_dereference_no_file() { + new_ucmd!() + .args(&["-h", "not-a-file"]) + .fails() + .stderr_contains("setting times of 'not-a-file': No such file or directory"); + new_ucmd!() + .args(&["-h", "not-a-file-1", "not-a-file-2"]) + .fails() + .stderr_contains("setting times of 'not-a-file-1': No such file or directory") + .stderr_contains("setting times of 'not-a-file-2': No such file or directory"); +}