From c64adee068036f4f931400622a47d553831ccfbc Mon Sep 17 00:00:00 2001 From: VenetiaFurtado <128660498+VenetiaFurtado@users.noreply.github.com> Date: Sun, 29 Jun 2025 07:26:33 -0600 Subject: [PATCH] touch: add -f flag (#8274) * touch: fix f flag * Update src/uu/touch/src/touch.rs Co-authored-by: Sylvestre Ledru * touch: add test for f flag * Update src/uu/touch/src/touch.rs Co-authored-by: Daniel Hofstetter * Update tests/by-util/test_touch.rs Co-authored-by: Daniel Hofstetter * remove unnecessary comment --------- Co-authored-by: Sylvestre Ledru Co-authored-by: Daniel Hofstetter --- src/uu/touch/src/touch.rs | 8 ++++++++ tests/by-util/test_touch.rs | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 9bc00379c..77a7e05a6 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -99,6 +99,7 @@ pub mod options { pub static NO_CREATE: &str = "no-create"; pub static NO_DEREF: &str = "no-dereference"; pub static TIME: &str = "time"; + pub static FORCE: &str = "force"; } static ARG_FILES: &str = "files"; @@ -291,6 +292,13 @@ pub fn uu_app() -> Command { .value_name("STRING") .conflicts_with(options::sources::TIMESTAMP), ) + .arg( + Arg::new(options::FORCE) + .short('f') + .help("(ignored)") + .hide(true) + .action(ArgAction::SetTrue), + ) .arg( Arg::new(options::MODIFICATION) .short('m') diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index 746d21704..3b742ea21 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -1006,3 +1006,14 @@ fn test_obsolete_posix_format_with_year() { assert!(at.file_exists("11111111")); assert!(!at.file_exists("0101000090")); } + +#[test] +fn test_touch_f_option() { + let (at, mut ucmd) = at_and_ucmd!(); + let file = "test_f_option.txt"; + + ucmd.args(&["-f", file]).succeeds().no_output(); + + assert!(at.file_exists(file)); + at.remove(file); +}