From 31875a241fc1b1c3582b8e876cf3c44d1145d468 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 2 Jun 2021 23:43:16 +0200 Subject: [PATCH] touch/gnu compat: 'touch no-file' exit code should be 1 --- src/uu/touch/src/touch.rs | 1 + tests/by-util/test_touch.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index ed65cb659..1b560553f 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -168,6 +168,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if let Err(e) = File::create(path) { show_warning!("cannot touch '{}': {}", path, e); + error_code = 1; continue; }; diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index cd780f670..c861a50dd 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -459,3 +459,10 @@ fn test_touch_system_fails() { .fails() .stderr_contains("setting times of '/'"); } + +#[test] +fn test_touch_trailing_slash() { + let (_at, mut ucmd) = at_and_ucmd!(); + let file = "no-file/"; + ucmd.args(&[file]).fails(); +}