du/ls: Unify file metadata time handling#8396
Merged
cakebaker merged 7 commits intouutils:mainfrom Jul 27, 2025
Merged
Conversation
This function is useful for more than `ls` (`du` can use it too).
…t_time Removes some duplicated code, with slight, but incorrect, differences.
No need to have separate struct creation code for Windows and Unix. Also remove is_dir, we can get it from metadata.
We assume that the string has been validated by clap ahead of time (just like the current code does).
Easier to just move the change time logic to another function.
It turns out `du` used to test for the wrong thing, `ctime` is the change timestamp, not creation time. We have to rely on a regex again, as the change timestamp is the current time.
|
GNU testsuite comparison: |
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Was meant to be a maybe-not-that-useful refactoring, uncovered a bug in
du...ctimeis change time, not modification time.du/test_du: Fix ctime fallback on Windows, and test
test_du: Fix --time=ctime test
It turns out
duused to test for the wrong thing,ctimeisthe change timestamp, not creation time.
We have to rely on a regex again, as the change timestamp is the
current time.
uucore: fsext: Deduplicate metadata_get_time
Easier to just move the change time logic to another function.
uucore: fsext: Provide From<&str> helper for MetadataTimeField
We assume that the string has been validated by clap ahead of
time (just like the current code does).
du: Simplify Stat creation further
No need to have separate struct creation code for Windows and Unix.
Also remove is_dir, we can get it from metadata.
du: Keep metadata in Stat, and make use of uucore::fsext::metadata_get_time
Removes some duplicated code, with slight, but incorrect, differences.
uucore: fsext: Move metadata_get_time from ls
This function is useful for more than
ls(ducan use it too).