Skip to content

Commit 75a540b

Browse files
committed
Use libc::UTIME_NOW in touch when updating time to now
1 parent efa1aa7 commit 75a540b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/uu/touch/src/touch.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6-
// spell-checker:ignore (ToDO) filetime datetime lpszfilepath mktime DATETIME datelike timelike
6+
// spell-checker:ignore (ToDO) filetime datetime lpszfilepath mktime DATETIME datelike timelike UTIME
77
// spell-checker:ignore (FORMATS) MMDDhhmm YYYYMMDDHHMM YYMMDDHHMM YYYYMMDDHHMMS
88

99
pub mod error;
@@ -377,6 +377,16 @@ pub fn touch(files: &[InputFile], opts: &Options) -> Result<(), TouchError> {
377377
(atime, mtime)
378378
}
379379
Source::Now => {
380+
#[cfg(unix)]
381+
let now: FileTime;
382+
{
383+
if opts.date.is_none() {
384+
now = FileTime::from_unix_time(0, libc::UTIME_NOW as u32);
385+
} else {
386+
now = datetime_to_filetime(&Local::now());
387+
}
388+
}
389+
#[cfg(not(unix))]
380390
let now = datetime_to_filetime(&Local::now());
381391
(now, now)
382392
}

tests/by-util/test_touch.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,3 +1052,10 @@ fn test_touch_non_utf8_paths() {
10521052
scene.ucmd().arg(non_utf8_name).succeeds().no_output();
10531053
assert!(std::fs::metadata(at.plus(non_utf8_name)).is_ok());
10541054
}
1055+
1056+
#[test]
1057+
#[cfg(target_os = "linux")]
1058+
fn test_touch_dev_full() {
1059+
let (_, mut ucmd) = at_and_ucmd!();
1060+
ucmd.args(&["/dev/full"]).succeeds().no_output();
1061+
}

0 commit comments

Comments
 (0)