Skip to content

ls: validate --block-size before -h/--si overrides it - #16025

Open
Logic769 wants to merge 1 commit into
uutils:mainfrom
Logic769:ls-validate-block-size-order
Open

Logic769 wants to merge 1 commit into
uutils:mainfrom
Logic769:ls-validate-block-size-order

Conversation

@Logic769

Copy link
Copy Markdown
Contributor

ls --block-size=0 --si printed the listing and exited 0, because --si (or -h) appearing after --block-size made clap drop the block-size value before it was validated. GNU validates the argument as it is parsed, regardless of option order:

$ ls --block-size=0 --si a.txt
ls: invalid --block-size argument '0'

Validate every command-line --block-size value up front, so an invalid size is rejected even when a later -h/--si changes the display format. The existing last-one-wins behaviour between --block-size and -h/--si is unchanged.

Test: tests/by-util/test_ls.rs::test_ls_invalid_block_size (new cases for --block-size=0 --si and --block-size=invalid --human-readable).

Closes #16008

@Logic769
Logic769 force-pushed the ls-validate-block-size-order branch 2 times, most recently from fe5ed6c to c4dc7a7 Compare October 30, 2026 13:02
Comment thread src/uu/ls/src/ls.rs Resolved
Comment thread src/uu/ls/src/ls.rs Resolved
Comment thread tests/by-util/test_ls.rs Resolved
@sylvestre
sylvestre force-pushed the ls-validate-block-size-order branch from 22410bd to 183c419 Compare November 3, 2026 00:54
@sylvestre

Copy link
Copy Markdown
Contributor

clippy is sad on 7 jobs :)

@sylvestre

Copy link
Copy Markdown
Contributor

clippy is sad :), and a bunch of jobs are failing

@Logic769
Logic769 force-pushed the ls-validate-block-size-order branch from 183c419 to f7b9531 Compare November 3, 2026 15:43
@codspeed

codspeed Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 41.29%

3 warnings

⚠️ 8 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 9 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 9 benchmarks with a significant change ran on a different major version of their CodSpeed integration

Their head results were measured with codspeed-rust 6.1.0, a different major version than their base results. A major version can change how benchmarks are measured, so the changes might come from this version difference rather than from the code. Comparisons between runs on the same major version are not affected.

See affected benchmarks

❌ 9 regressed benchmarks
✅ 7 untouched benchmarks
⏩ 468 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory ls_recursive_long_all_deep_tree[(100, 4)] 117 KB 307.7 KB -61.99%
❌ Memory ls_recursive_long_all_mixed_tree 118.4 KB 309.2 KB -61.7%
❌ Memory ls_recursive_balanced_tree[(6, 4, 15)] 111.1 KB 208.4 KB -46.69%
❌ Memory ls_recursive_mixed_tree 117.9 KB 215.2 KB -45.21%
❌ Memory ls_recursive_deep_tree[(200, 2)] 125 KB 222.3 KB -43.78%
❌ CPU Simulation ls_recursive_long_all_mixed_tree 4.5 ms 6.9 ms -34.22%
❌ CPU Simulation ls_recursive_long_all_deep_tree[(100, 4)] 4.8 ms 7.1 ms -33.13%
❌ CPU Simulation ls_recursive_mixed_tree 2.4 ms 2.8 ms -13.3%
❌ CPU Simulation ls_recursive_deep_tree[(200, 2)] 2.9 ms 3.2 ms -9.13%

Tip

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


Comparing Logic769:ls-validate-block-size-order (15b2002) with main (12953e7)2

Open in CodSpeed

Footnotes

  1. 468 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. ↩

  2. No successful run was found on main (08dd9f2) during the generation of this report, so 12953e7 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@sylvestre
sylvestre force-pushed the ls-validate-block-size-order branch from f7b9531 to 22a74ac Compare November 6, 2026 11:34
@Logic769
Logic769 force-pushed the ls-validate-block-size-order branch from 22a74ac to f0be489 Compare November 16, 2026 04:11
@sylvestre

Copy link
Copy Markdown
Contributor

thanks for working on this!
The fix works, but it now panics through expect because each value is parsed twice (see inline). CI is also red.
Please squash the 4 commits into one.

@Logic769
Logic769 force-pushed the ls-validate-block-size-order branch from f0be489 to 2a82962 Compare November 16, 2026 12:22
Comment thread src/uu/ls/src/config.rs Resolved
Comment thread src/uu/ls/src/config.rs Resolved
Comment thread tests/by-util/test_ls.rs Resolved
@Logic769
Logic769 force-pushed the ls-validate-block-size-order branch from 2a82962 to 144fd4f Compare November 16, 2026 21:09
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/tail/truncate. tests/tail/truncate is passing on 'main'. Maybe you have to rebase?

@sylvestre
sylvestre force-pushed the ls-validate-block-size-order branch from 144fd4f to f56d760 Compare November 17, 2026 16:01
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.48 MB (+100 KB, +0.06%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

@Logic769
Logic769 force-pushed the ls-validate-block-size-order branch from f56d760 to 7afbaa9 Compare November 18, 2026 04:38
@Logic769

Copy link
Copy Markdown
Contributor Author

CI note: the Aggregate GNU test results job reports a single new failure, tests/tail/truncate, but this PR only changes src/uu/ls and tests/by-util/test_ls.rs.

The same branch's previous GnuTests run on commit f56d760 (run 44120974514) passed, and there are no tail changes between the branch base and current main. The test output is simply 1..10 followed by FAIL tests/tail/truncate.sh, which looks like an intermittent timing failure in the GNU testsuite runner rather than a regression from this PR. Re-running the GnuTests workflow should clear it.

@sylvestre
sylvestre force-pushed the ls-validate-block-size-order branch from 7afbaa9 to 63d5e0f Compare November 18, 2026 22:02
Comment thread src/uu/ls/src/config.rs Resolved
Comment thread src/uu/ls/src/config.rs Resolved
Comment thread src/uu/ls/src/ls.rs Resolved
@Logic769
Logic769 force-pushed the ls-validate-block-size-order branch from 63d5e0f to b99c19f Compare November 20, 2026 09:10
--block-size is now collected with clap (ArgAction::Append) so that every
value given is validated, even when a later -h/--si overrides it; the error
keeps the caret under the offending value.

Each value is parsed exactly once and the parsed size is carried along in
SizeMode, so nothing is parsed twice and there is no expect()/panic path left.
@sylvestre
sylvestre force-pushed the ls-validate-block-size-order branch from b99c19f to 15b2002 Compare November 21, 2026 17:42

This branch has not been deployed

No deployments
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.

ls: --block-size=0 is accepted when --si comes later

2 participants