From 13e912bcbd416a8bdcb4c07762983c1c0f1023f6 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Mon, 1 Aug 2022 10:04:49 +0300 Subject: [PATCH] touch: fix error handling --- src/uu/touch/src/touch.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index bcb0beaca..e8c4fcd2f 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -103,7 +103,11 @@ Try 'touch --help' for more information."##, let path = pathbuf.as_path(); - if !path.exists() { + if let Err(e) = path.metadata() { + if e.kind() != std::io::ErrorKind::NotFound { + return Err(e.map_err_context(|| format!("setting times of {}", filename.quote()))); + } + if matches.contains_id(options::NO_CREATE) { continue; }