1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

touch: support obsolete POSIX timestamp argument

Support obsolete form of timestamp argument for old POSIX versions. In
summary, when older versions of POSIX are used and the first positional
argument looks like a date and time, then treat it as a timestamp
instead of as a filename. For example, before this commit

    _POSIX2_VERSION=199209
    POSIXLY_CORRECT=1
    touch 01010000 11111111

would create two files, `01010000` and `11111111`. After this commit,
the first argument is interpreted as a date and time (in this case,
midnight on January 1 of the current year) and that date and time are
set on the file named `11111111`.

Fixes #7180.
This commit is contained in:
Jeffrey Finkelstein 2025-02-03 20:24:45 -05:00
parent ee0d178f8c
commit 6dfa1f8276
2 changed files with 93 additions and 14 deletions

View file

@ -917,3 +917,27 @@ fn test_touch_reference_symlink_with_no_deref() {
// Times should be taken from the symlink, not the destination
assert_eq!((time, time), get_symlink_times(&at, arg));
}
#[test]
fn test_obsolete_posix_format() {
let (at, mut ucmd) = at_and_ucmd!();
ucmd.env("_POSIX2_VERSION", "199209")
.env("POSIXLY_CORRECT", "1")
.args(&["01010000", "11111111"])
.succeeds()
.no_output();
assert!(at.file_exists("11111111"));
assert!(!at.file_exists("01010000"));
}
#[test]
fn test_obsolete_posix_format_with_year() {
let (at, mut ucmd) = at_and_ucmd!();
ucmd.env("_POSIX2_VERSION", "199209")
.env("POSIXLY_CORRECT", "1")
.args(&["9001010000", "11111111"])
.succeeds()
.no_output();
assert!(at.file_exists("11111111"));
assert!(!at.file_exists("01010000"));
}