Skip to content

Fix touch -t with 2 digit years when YY > 68 #7378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2025
Merged

Conversation

Carreau
Copy link
Contributor

@Carreau Carreau commented Mar 2, 2025

When using touch -t with a 2 digit year, the year is interpreted as a relative year to 2000.

When the year is 68 or less, it should be interpreted as 20xx. When the year is 69 or more, it should be interpreted as 19xx.

This is the behavior of GNU touch.

fixes gh-7280

Arguably 2 digits years should be deprecated as we are already closer to 2069, than 1969.

@Carreau
Copy link
Contributor Author

Carreau commented Mar 2, 2025

I'm fairly new to rust, so I'm sure it can be improved.

Otherwise I've quite a bit of experience under my belt as a maintainer myself, so you can stay terse in your requests and explanations, I know time can be precious.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR fixes the logic for interpreting 2-digit years in the touch command, aligning its behavior with GNU touch.

  • Introduces a helper function to prepend "19" or "20" to 2-digit year strings based on their value.
  • Updates the timestamp parsing logic to utilize the new helper function.
  • Adds tests to verify correct behavior for both 2-digit year ranges.

Reviewed Changes

File Description
src/uu/touch/src/touch.rs New helper function for determining century based on a 2-digit year is added and integrated into the timestamp parser.
tests/by-util/test_touch.rs Added tests to confirm that 2-digit years are correctly interpreted as 20xx or 19xx based on their value.

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@Carreau Carreau force-pushed the touch-t branch 2 times, most recently from 4588d36 to 15d3cdc Compare March 3, 2025 15:55
Copy link

github-actions bot commented Mar 3, 2025

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@Carreau
Copy link
Contributor Author

Carreau commented Mar 3, 2025

One of the failure:

assertion `atime == expected` failed
  left: FileTime { seconds: -1202365696, nanos: 0 }
 right: FileTime { seconds: 3092601600, nanos: 0 }

The difference in seconds is exactly 2**32. I'm not sure why this could be.

@Carreau
Copy link
Contributor Author

Carreau commented Mar 4, 2025

(workflows need approval after the recent force-push)

@Carreau
Copy link
Contributor Author

Carreau commented Mar 4, 2025

for what it is worth, I think gnu touch behaviors comes from gnulib's parse-datetime.y to_tm_year(), I don't know if it should be reported as potentially problematic in 44 years.

Carreau pushed a commit to Carreau/coreutils that referenced this pull request Mar 4, 2025
It's unclear to me how the failure seen in uutils#7378
is related to the change in the PR, it just happen
that the test need to try touching in 2068.
The 2^32 error in the test makes me strongly think
of  the year 2038 bug, so I added a test for that.
Carreau pushed a commit to Carreau/coreutils that referenced this pull request Mar 4, 2025
It's unclear to me how the failure seen in uutils#7378
is related to the change in the PR, it just happen
that the test need to try touching in 2068.
The 2^32 error in the test makes me strongly think
of  the year 2038 bug, so I added a test for that.
Carreau pushed a commit to Carreau/coreutils that referenced this pull request Mar 4, 2025
It's unclear to me how the failure seen in uutils#7378
is related to the change in the PR, it just happen
that the test need to try touching in 2068.
The 2^32 error in the test makes me strongly think
of  the year 2038 bug, so I added a test for that.
Carreau pushed a commit to Carreau/coreutils that referenced this pull request Mar 4, 2025
It's unclear to me how the failure seen in uutils#7378
is related to the change in the PR, it just happen
that the test need to try touching in 2068.
The 2^32 error in the test makes me strongly think
of  the year 2038 bug, so I added a test for that.
@Carreau
Copy link
Contributor Author

Carreau commented Mar 4, 2025

Failures seem to be read y2038 bug (see #7399), but I don't know if this bug should be ignored, or fixed on relevant platform, and which/if #[cfg()] to apply to the tests

@RenjiSann
Copy link
Collaborator

Failures seem to be read y2038 bug (see #7399), but I don't know if this bug should be ignored, or fixed on relevant platform, and which/if #[cfg()] to apply to the tests

#[cfg(target_pointer_width = "64")] according to Stack Overflow

Copy link

github-actions bot commented Mar 5, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

RenjiSann pushed a commit to Carreau/coreutils that referenced this pull request Mar 6, 2025
It's unclear to me how the failure seen in uutils#7378
is related to the change in the PR, it just happen
that the test need to try touching in 2068.
The 2^32 error in the test makes me strongly think
of  the year 2038 bug, so I added a test for that.
RenjiSann pushed a commit to Carreau/coreutils that referenced this pull request Mar 10, 2025
It's unclear to me how the failure seen in uutils#7378
is related to the change in the PR, it just happen
that the test need to try touching in 2068.
The 2^32 error in the test makes me strongly think
of  the year 2038 bug, so I added a test for that.
M Bussonnier added 2 commits March 12, 2025 12:03
When using `touch -t` with a 2 digit year, the year is interpreted as
a relative year to 2000.

When the year is 68 or less, it should be interpreted as 20xx.
When the year is 69 or more, it should be interpreted as 19xx.

This is the behavior of GNU `touch`.

fixes uutilsgh-7280

Arguably 2 digits years should be deprecated as we
are already closer to 2069, than 1969.
@RenjiSann RenjiSann merged commit 57d0157 into uutils:main Mar 14, 2025
66 checks passed
Carreau pushed a commit to Carreau/coreutils that referenced this pull request Mar 15, 2025
It's unclear to me how the failure seen in uutils#7378
is related to the change in the PR, it just happen
that the test need to try touching in 2068.
The 2^32 error in the test makes me strongly think
of  the year 2038 bug, so I added a test for that.
Carreau pushed a commit to Carreau/coreutils that referenced this pull request Apr 28, 2025
It's unclear to me how the failure seen in uutils#7378
is related to the change in the PR, it just happen
that the test need to try touching in 2068.
The 2^32 error in the test makes me strongly think
of  the year 2038 bug, so I added a test for that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

touch: -t YYMMDDhhmm leads to incorrect year if YY > 68
4 participants