Skip to content

Conversation

@Alonely0
Copy link
Contributor

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

Fixes issue uutils#9072, where some AppArmor profiles designed for GNU coreutils would break under uutils because we would fetch this info unnecessarily.
Fixes issue uutils#9071, where the default options for the `Device` field where incorrect, as well as several format flags that were not working as intended: %R, %Hr, %Lr, %Hd, %Ld, %t.
Previosuly, stat would ignore the next char after escaping it; e.g., "%%m" would become "%" instead of literally "%m".
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 29, 2025

CodSpeed Performance Report

Merging #9078 will degrade performances by 3.96%

Comparing Alonely0:stat_fix (e8bc453) with main (3a44280)

Summary

❌ 4 regressions
✅ 100 untouched
🗄️ 1 archived benchmark run1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
du_balanced_tree[(5, 4, 10)] 9.1 ms 9.3 ms -2.72%
du_human_balanced_tree[(5, 4, 10)] 10.1 ms 10.5 ms -3.96%
du_max_depth_balanced_tree[(6, 4, 10)] 32.3 ms 33 ms -2.22%
du_summarize_balanced_tree[(5, 4, 10)] 8.3 ms 8.5 ms -2.42%

Footnotes

  1. 1 benchmark was run, but is now archived. If it was deleted in another branch, consider rebasing to remove it from the report. Instead if it was added back, click here to restore it.

@Alonely0
Copy link
Contributor Author

I mean, that's not my fault lol.

@github-actions
Copy link

GNU testsuite comparison:

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

@rlee287
Copy link

rlee287 commented Oct 29, 2025

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.

@Alonely0
Copy link
Contributor Author

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
Copy link
Contributor Author

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).

@github-actions
Copy link

GNU testsuite comparison:

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

@Alonely0
Copy link
Contributor Author

Alonely0 commented Oct 30, 2025

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 :) )

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.

Default output format of stat uses incorrect format for Device field

2 participants