Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/uu/stat/src/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,16 +544,18 @@ fn process_token_filesystem(
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.

// `+` and ` ` add a sign; the other counts are unsigned.
// free blocks available to non-superuser
'a' => OutputType::Unsigned(meta.avail_blocks()),
'a' => OutputType::Integer(meta.avail_blocks() as i64),
// total data blocks in file system
'b' => OutputType::Unsigned(meta.total_blocks()),
'b' => OutputType::Integer(meta.total_blocks() as i64),
// total file nodes in file system
'c' => OutputType::Unsigned(meta.total_file_nodes()),
// free file nodes in file system
'd' => OutputType::Unsigned(meta.free_file_nodes()),
'd' => OutputType::Integer(meta.free_file_nodes() as i64),
// free blocks in file system
'f' => OutputType::Unsigned(meta.free_blocks()),
'f' => OutputType::Integer(meta.free_blocks() as i64),
// file system ID in hex
'i' => OutputType::UnsignedHex(meta.fsid()),
// maximum length of filenames
Expand Down
19 changes: 19 additions & 0 deletions tests/by-util/test_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,25 @@ fn test_printf_invalid_directive() {
.stderr_contains("'%9%': invalid directive");
}

#[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.

// while the unsigned counts (%c, %s) ignore them.
let out = new_ucmd!()
.args(&["-f", "--printf=%+a|% b|%+d|%+f|%+c|%+s", "."])
.succeeds()
.stdout_move_str();
let fields: Vec<&str> = out.split('|').collect();
assert!(fields[0].starts_with('+'), "{out}");
assert!(fields[1].starts_with(' '), "{out}");
assert!(fields[2].starts_with('+'), "{out}");
assert!(fields[3].starts_with('+'), "{out}");
for unsigned in &fields[4..] {
assert!(unsigned.chars().all(|c| c.is_ascii_digit()), "{out}");
}
}

#[test]
fn test_invalid_directive_after_multibyte_char() {
let ts = TestScenario::new(util_name!());
Expand Down
Loading