Skip to content

ls, df: preserve suffix-only block size units - #14390

Open
Socialpranker wants to merge 2 commits into
uutils:mainfrom
Socialpranker:feat/ls-df-blocksize-suffix
Open

ls, df: preserve suffix-only block size units#14390
Socialpranker wants to merge 2 commits into
uutils:mainfrom
Socialpranker:feat/ls-df-blocksize-suffix

Conversation

@Socialpranker

@Socialpranker Socialpranker commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

ls -l --block-size=K and df --block-size=K printed a bare number where GNU
echoes the unit back: 1K, not 1. A spec with a leading number
(--block-size=1K, --block-size=1024) only sets the divisor and echoes
nothing. Same for LS_BLOCK_SIZE, BLOCK_SIZE, BLOCKSIZE, DF_BLOCK_SIZE.
-h/--si are unaffected.

This is the gap noted in #14330's description; #13655 fixes the same defect for
du (it touches only du.rs, no conflict).

Two commits: df (+ the shared uucore helpers) first, ls on top. Each
builds and tests on its own.

Verified byte-for-byte against GNU coreutils 9.11 (gls/gdf) over 12
block-size specs x ls -l, -s, total, and the env vars. New tests in
test_ls.rs, test_df.rs, plus unit tests in uucore.

Prepared with AI assistance (Claude Sonnet 5, via Claude Code), per the AI
policy in CONTRIBUTING.md. GNU behavior came from running the binary, not from
reading GPL source.

@sylvestre

Copy link
Copy Markdown
Contributor

could you please make comment #0 a bit shorter ? nobody likes reading long llm output ;)

Comment thread src/uu/df/src/blocks.rs Outdated
Comment on lines +127 to +132
/// The default variant is `Bytes(1024, None)`.
///
/// The second field is the GNU-style display suffix (e.g. `"K"`) to echo
/// back next to a scaled number, set only when the block size was given as
/// a suffix-only spec (`--block-size=K`) rather than a numeric one
/// (`--block-size=1K`, `--block-size=1024`).

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.

make this comment shorter

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.

Cut to 3 lines with the example inline.

Comment thread src/uu/ls/src/config.rs Outdated
fn resolve_block_sizes_from_env(opt_kb: bool) -> (u64, u64) {
match parse_block_size::block_size_from_env(&["LS_BLOCK_SIZE", "BLOCK_SIZE"]) {
parse_block_size::BlockSizeEnv::Found(size) => {
/// `BLOCKSIZE` only affects the allocation display (`-s`), not file sizes.

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.

same, this comment is too long

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.

Cut to 4 lines.

BlockSizeEnv::NotSet
}

/// Extract the display suffix from a block-size spec, if the spec is

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.

i don't think we need 14 lines of comments
esp when they don't follow rustdoc format or provide an example

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.

Down to 2 lines plus a rustdoc example.

Comment thread src/uu/ls/src/config.rs Outdated
const DEFAULT_FILE_SIZE_BLOCK_SIZE: u64 = 1;

/// Resolve `(file_size_block_size, block_size)` from environment variables.
/// The block sizes `ls` displays with, plus the display suffixes that go

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 do a gh stack and move ls in the second commit of the stack

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.

Split: df + the uucore helpers first, ls on top. Each commit builds and tests alone. Happy to split into two PRs if you'd rather have a real stack.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/dd/no-allocate is now being skipped but was previously passing.
Congrats! The gnu test tests/tail/pipe-f is now passing!

GNU echoes the unit back next to the number when --block-size (or
DF_BLOCK_SIZE/BLOCK_SIZE/BLOCKSIZE) is given as a bare unit
(--block-size=K -> "1K"), but not when a numeric multiplier is given
(--block-size=1K or --block-size=1024 -> "1"). uutils printed a bare
number in both cases.

Adds suffix_from_parsed_block_size and block_size_from_env_with_suffix
to uucore's parse_block_size; df's BlockSize now carries an optional
display suffix, which also lets the header keep a full IEC spelling
(--block-size=KiB -> "1KiB-blocks").
Same rule as the previous commit, applied to ls: --block-size=K (and
LS_BLOCK_SIZE/BLOCK_SIZE/BLOCKSIZE) echoes the unit next to the size,
--block-size=1K does not.

ls tracks the file-size and allocation suffixes separately, since
BLOCKSIZE only affects the allocation column (-s and the total line)
and must not leak into the -l size column. -k resets the allocation
block size and its unit, leaving a file-size unit from the environment
alone, matching GNU.
@Socialpranker
Socialpranker force-pushed the feat/ls-df-blocksize-suffix branch from 0d0a1e1 to b2e2527 Compare September 5, 2026 19:46
@Socialpranker

Copy link
Copy Markdown
Contributor Author

Comments trimmed throughout the diff (longest was 14 lines, now 2 + an example), and split into two commits: df + uucore helpers, then ls. Body shortened too.

@codspeed-hq

codspeed-hq Bot commented Sep 5, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 3.43%

❌ 1 regressed benchmark
✅ 366 untouched benchmarks
⏩ 50 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation du_deep_tree[(100, 3)] 2.1 ms 2.2 ms -3.43%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Socialpranker:feat/ls-df-blocksize-suffix (b2e2527) with main (9ff4114)

Open in CodSpeed

Footnotes

  1. 50 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.

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.

2 participants