coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

fix(stat): Collection of fixes for stat(1)

Open Alonely0 opened this issue 1 month ago • 10 comments

This PR fixes #9071, #9072, as well as a few bugs found along the way.

Alonely0 avatar Oct 29 '25 14:10 Alonely0

CodSpeed Performance Report

Merging #9078 will not alter performance

Comparing Alonely0:stat_fix (55eee3e) with main (aaa0610)

Summary

✅ 127 untouched
⏩ 6 skipped[^skipped]

[^skipped]: 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

codspeed-hq[bot] avatar Oct 29 '25 15:10 codspeed-hq[bot]

I mean, that's not my fault lol.

Alonely0 avatar Oct 29 '25 15:10 Alonely0

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Oct 29 '25 15:10 github-actions[bot]

I think it'd be better to add tests for the device number and the percent escape issues as well.

For the percent escape issue, I propose the following addition to test_stat.rs:

#[test]
fn test_double_percent() {
    let ts = TestScenario::new(util_name!());
    let result = ts.ucmd().args(&["-c", "%%m", "/"]).succeeds();
    let output = result.stdout_str().trim();
    assert!(!output.is_empty(), "Escaped percent should be present");
    assert_eq!(output, "%m");
}

For the device number format issue, I'd add %Hd %Ld %r %R %Hr %Lr to one of NORMAL_FORMAT_STR, DEV_FORMAT_STR, or FS_FORMAT_STR in test_stat.rs, but I'm not familiar enough with the purpose of each of those to suggest which one(s) they should be added to.

rlee287 avatar Oct 29 '25 17:10 rlee287

Yeah I agree, I'll add a few tests :). Ngl, I was trying to cut that corner cuz tomorrow I got an exam, but it should be quick enough.

Alonely0 avatar Oct 29 '25 18:10 Alonely0

Testing the value of these flags (%Hd %Ld %r %R %Hr %Lr) is actually correct is quite difficult without bringing in the machine's stat as a reference, because their output is not trivial. Rn, in CI it's probably either GNU or busybox, but knowing Ubuntu's switched to uutils we might as well be testing against an older version of uutils in the future. This is why I'm choosing against including that test, and only one about percent escaping. Maintainers, lmk if you would like me to include it nevertheless (it's already written lol).

Alonely0 avatar Oct 29 '25 18:10 Alonely0

GNU testsuite comparison:

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

github-actions[bot] avatar Oct 29 '25 19:10 github-actions[bot]

Those CI fails are still not my fault :) Also, I'll probably be opening a few PRs with perf improvements, passes of clippy nightly, and I'll probably refactor stat's format parser so it's less spaghetti-y; iirc stat is not the only coreutil that does use percent escaping (ls, date, du and printf come to my mind) so I feel strongly like adding a general impl to uu_core or common and refactoring these other coreutils. If you approve, I'll have it done by the end of next week (I'm done w/ my exams on Wednesday :) )

Alonely0 avatar Oct 30 '25 11:10 Alonely0

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/cksum/b2sum is no longer failing!

github-actions[bot] avatar Dec 08 '25 20:12 github-actions[bot]

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/cksum/b2sum is no longer failing!

github-actions[bot] avatar Dec 09 '25 07:12 github-actions[bot]