Skip to content

stat: print the -f block and free node counts signed, as GNU does - #15355

Closed
ozenyunus35 wants to merge 2 commits into
uutils:mainfrom
ozenyunus35:stat-fs-signed-counts
Closed

ozenyunus35 wants to merge 2 commits into
uutils:mainfrom
ozenyunus35:stat-fs-signed-counts

Conversation

@ozenyunus35

Copy link
Copy Markdown
Contributor

GNU prints %a, %b, %d and %f of stat -f with out_int, which keeps the + and flags, so stat -f -c %+b / gives +120699413. We printed them unsigned and dropped the flags. The other counts (%c, %s, %S) go through out_uint in GNU and stay unsigned here too.

Added test_fs_signed_counts_take_sign_flags (Linux, Android, macOS, where stat -f is implemented), which fails without the change.

This sits next to #15352, which makes %s/%S unsigned; the two touch neighbouring lines of the -f match, so whichever lands second may need a quick rebase, and I'll take care of it.

I used an AI assistant to help draft parts of the code and tests; I reviewed the changes and ran the tests myself.

GNU prints %a, %b, %d and %f of `stat -f` with out_int, so the `+` and
` ` flags add a sign: `stat -f -c %+b /` gives `+123`. We printed them
unsigned and dropped the flags.
Comment thread src/uu/stat/src/stat.rs Outdated
format,
} => {
let output = match format {
// GNU prints the block and free node counts signed (`out_int`), so

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please drop the out_int reference, we don't refer to GNU internals. "signed, so + and apply" is enough

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, it now just says the counts are signed so + and apply.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I hope by "we don't refer to GNU internals", you mean you don't copy from GNU internals, not just that you keep it secret... It is frustrating to see this, yet again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right, and I'm sorry. This change came from reading GNU's stat.c, which uutils doesn't allow. I'm closing this PR, and I've also removed the part of #15352 that came from the same source.

Comment thread tests/by-util/test_stat.rs Outdated
#[test]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))]
fn test_fs_signed_counts_take_sign_flags() {
// GNU prints %a, %b, %d and %f signed, so `+` and ` ` add a sign there,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this comment repeats the one in stat.rs, could be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.

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.

3 participants