Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions src/uu/stat/src/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,16 +544,17 @@ fn process_token_filesystem(
format,
} => {
let output = match format {
// The block and free node counts are signed, so `+` and ` ` apply.
// 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
17 changes: 17 additions & 0 deletions tests/by-util/test_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,23 @@ 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() {
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