Skip to content
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

Fix stat on files with timestamps before the epoch #1250

Merged
merged 3 commits into from
Jan 15, 2024

Conversation

joshtriplett
Copy link
Contributor

stat converted the seconds to a u64 before converting them to
SystemTime. This would cause timestamps before the epoch to wrap around
to timestamps near u64::MAX.

Instead, pass the seconds as an i64. Convert it to SystemTime by
computing an absolute Duration and then adding or subtracting as
appropriate.

Byron and others added 2 commits January 15, 2024 09:17
stat converted the seconds to a `u64` before converting them to
SystemTime. This would cause timestamps before the epoch to wrap around
to timestamps near `u64::MAX`.

Instead, pass the seconds as an i64. Convert it to SystemTime by
computing an absolute Duration and then adding or subtracting as
appropriate.
@Byron Byron force-pushed the fix-stat-with-negative-times branch from 2634440 to 3cd6a41 Compare January 15, 2024 08:29
Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

I have added the test which exposed yet another issue specific to MacOS, and one that fortunately we already encountered and solved :D.

Will merge when CI is green and create a new release of gix-index which fortunately didn't encounter any breaking changes, making a patch-release possible.

@Byron Byron force-pushed the fix-stat-with-negative-times branch from 3cd6a41 to 7ce455c Compare January 15, 2024 09:23
Copied from https://github.com/rust-lang/rust at a8ece1190bf6b340175bc5b688e52bd29924f483
@Byron Byron force-pushed the fix-stat-with-negative-times branch from 7ce455c to bf49cd4 Compare January 15, 2024 09:48
@Byron
Copy link
Member

Byron commented Jan 15, 2024

Now there is bytecodealliance/rustix#990 which, if accepted, would probably alleviate the need to cast to i64 explicitly. However, doing so also makes sense to protect from future issues of this kind, so I will probably leave it as is even if the PR gets merged.

@Byron Byron merged commit 08e6ca8 into GitoxideLabs:main Jan 15, 2024
18 checks passed
@Byron
Copy link
Member

Byron commented Jan 15, 2024

And finally, the there is a new release with the fix: https://github.com/Byron/gitoxide/releases/tag/gix-index-v0.28.2 .

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.

2 participants