diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index e00c1df82..bde22ab33 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -// spell-checker:ignore (ToDO) filetime datetime lpszfilepath mktime DATETIME datelike timelike +// spell-checker:ignore (ToDO) filetime datetime lpszfilepath mktime DATETIME datelike timelike UTIME // spell-checker:ignore (FORMATS) MMDDhhmm YYYYMMDDHHMM YYMMDDHHMM YYYYMMDDHHMMS pub mod error; @@ -23,6 +23,8 @@ use std::io::{Error, ErrorKind}; use std::path::{Path, PathBuf}; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; +#[cfg(target_os = "linux")] +use uucore::libc; use uucore::parser::shortcut_value_parser::ShortcutValueParser; use uucore::translate; use uucore::{format_usage, show}; @@ -377,7 +379,19 @@ pub fn touch(files: &[InputFile], opts: &Options) -> Result<(), TouchError> { (atime, mtime) } Source::Now => { - let now = datetime_to_filetime(&Local::now()); + let now: FileTime; + #[cfg(target_os = "linux")] + { + if opts.date.is_none() { + now = FileTime::from_unix_time(0, libc::UTIME_NOW as u32); + } else { + now = datetime_to_filetime(&Local::now()); + } + } + #[cfg(not(target_os = "linux"))] + { + now = datetime_to_filetime(&Local::now()); + } (now, now) } &Source::Timestamp(ts) => (ts, ts), diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index 680758672..eb2b5c02f 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -1052,3 +1052,10 @@ fn test_touch_non_utf8_paths() { scene.ucmd().arg(non_utf8_name).succeeds().no_output(); assert!(std::fs::metadata(at.plus(non_utf8_name)).is_ok()); } + +#[test] +#[cfg(target_os = "linux")] +fn test_touch_dev_full() { + let (_, mut ucmd) = at_and_ucmd!(); + ucmd.args(&["/dev/full"]).succeeds().no_output(); +}