From d5569847bd682f0df1eab95316fa9c81afe83676 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 8 May 2022 21:31:42 +0200 Subject: [PATCH] also support for tests/touch/no-rights.sh format --- src/uu/touch/src/touch.rs | 15 ++++++++++++++- tests/by-util/test_touch.rs | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index c082aed23..5444c8c10 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -280,12 +280,20 @@ const YYYYMMDDHHMMSS_FORMAT: &[time::format_description::FormatItem] = format_de "[year repr:full]-[month repr:numerical padding:zero]-\ [day] [hour]:[minute]:[second].[subsecond]" ); + // "%Y-%m-%d %H:%M:%S" 12 chars const YYYYMMDDHHMMS_FORMAT: &[time::format_description::FormatItem] = format_description!( "[year repr:full]-[month repr:numerical padding:zero]-\ [day] [hour]:[minute]:[second]" ); +// "%Y-%m-%d %H:%M" 12 chars +// Used for example in tests/touch/no-rights.sh +const YYYY_MM_DD_HH_MM_FORMAT: &[time::format_description::FormatItem] = format_description!( + "[year repr:full]-[month repr:numerical padding:zero]-\ + [day] [hour]:[minute]" +); + // "%Y%m%d%H%M" 12 chars const YYYYMMDDHHMM_FORMAT: &[time::format_description::FormatItem] = format_description!( "[year repr:full][month repr:numerical padding:zero]\ @@ -325,7 +333,12 @@ fn parse_date(s: &str) -> UResult { // Also support other formats found in the GNU tests like // in tests/misc/stat-nanoseconds.sh - for fmt in [YYYYMMDDHHMMS_FORMAT, YYYYMMDDHHMMSS_FORMAT] { + // or tests/touch/no-rights.sh + for fmt in [ + YYYYMMDDHHMMS_FORMAT, + YYYYMMDDHHMMSS_FORMAT, + YYYY_MM_DD_HH_MM_FORMAT, + ] { if let Ok(parsed) = time::PrimitiveDateTime::parse(s, &fmt) { return Ok(dt_to_filename(parsed)); } diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index 9b8eebbf0..5417a0dbe 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -469,6 +469,25 @@ fn test_touch_set_date5() { assert_eq!(mtime, expected); } +#[test] +fn test_touch_set_date6() { + let (at, mut ucmd) = at_and_ucmd!(); + let file = "test_touch_set_date"; + + ucmd.args(&["-d", "2000-01-01 00:00", file]) + .succeeds() + .no_stderr(); + + assert!(at.file_exists(file)); + + let expected = FileTime::from_unix_time(946684800, 0); + + let (atime, mtime) = get_file_times(&at, file); + assert_eq!(atime, mtime); + assert_eq!(atime, expected); + assert_eq!(mtime, expected); +} + #[test] fn test_touch_set_date_wrong_format() { let (_at, mut ucmd) = at_and_ucmd!();