Repository navigation
feat(ls): support -h human-readable sizes and -t/-S/-r sorting - #228
Conversation
4809f50 to
9a41af5
Compare
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Changes requested: one bug. The -h formatting is byte-identical to GNU, and sorting inside a directory matches GNU. But ls -t *.log | head -1, the usual way to get the newest file, now silently returns the alphabetically first file.
- 🔴
ls.rs:294:-t/-Sdon't reorder file operands, so any glob gets name order back. Before this PR,ls -tfailed withinvalid option. Now it gives a wrong answer that looks right. The PR calls this a follow-up, but I think it needs to land here: sort the operands with the same comparator, or reject-t/-Swhen there are several operands. Details inline.
Everything else is non-blocking (below).
✅ What I verified
- Head
9a41af5.cargo test --test shell_integration: 1629 passed. The 41ls_tests andhuman_size_matches_gnupass. human_sizeagainst GNU coreutils 9.1LC_ALL=C ls -lhon sparse files: 7,488 sizes (every K/M/G/T boundary ±3, tenths boundaries, random sizes up to 16T) with 0 mismatches. A second independent run of 6,494 sizes plusnumfmt --to=iec --round=upalso had 0 mismatches. A fuzz run up to u64::MAX (16E) agreed with the reference. No panic path: the largest exponent is 6, andSUFFIXEShas 8 entries.- Sorting on a direct bind against GNU: 38 of 48 cases pass. The passes cover
-t -tr -S -Sr -tS -St -r -at -aS -Rt -RS -lt -lS -ltr -lhS -lhtr --reverse, ties in name order, ties reversing under-r, the last of-t/-Swinning, and sub-second mtimes. Of the 10 failures, 7 are operands (the 🔴 above). The other 3 are things that already happen on main:./..under-la, #254, and globs not expanding on direct binds. - Scope fits #207 (P0:
ls -lhprinted help; P1:ls -t -S -h).-ris small and reasonable. - Evidence uploaded:
repro-ls-t-operands.txt,human-size-gnu-diff.log,sort-gnu-diff.log.
Appendix: non-blocking (5)
- ⚪
ls.rs:196and:225: with-lt/-lS, each entry islstated twice (sort key, then printing), and hidden entries arelstated even when skipped. Keeping theFileStatfrom the sort key would avoid that. On a direct bind it's twice the host syscalls. - ⚪
ls.rs:202:_ => b.1.cmp(&a.1)also matchesSortBy::Name, which can't happen inside this branch. WritingSortBy::Sizemakes the intent explicit. - ⚪
ls.rs:4-15: the new help rows (-h, --human-readable …) use a different column width from the old ones (-l …), so the descriptions don't line up. - ⚪
tests/shell_integration.rs:3614:-ltonly checks.last(). Checking the whole output would prove that complete rows move together. Nothing covers-Ror-acombined with a sort. - Already on main, not caused here:
- A blank line is printed between file operands (
ls n2 n1→n2\n\nn1). Fixing it alongside operand sorting would make sense. lstatfollows symlinks on direct binds, so-t/-Ssort symlinks by their target. Already filed as #254.ls /bound/dir/*.logdoesn't expand the glob on a direct bind. I didn't investigate the cause and haven't filed it.
- A blank line is printed between file operands (
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve. The 🔴 is fixed in b57f989: ls -t *.log | head -1 now returns the newest file, and file operands use the same comparator as directory entries.
- 🔴 operand sort: fixed. I attacked the fix too: reverse ties, files before directories under
-r, a mixedls -t d c.log a.log(→c.log a.log, blank line,d:), missing operands, and symlink-to-dir operands. All match GNU. - Appendix nits: fixed (single
lstat, hidden entries filtered before it, explicitSortByarms, full-row tests). One nit is left: the help text is still one column off, because the-h/-rdescriptions start at column 25 and the rest at column 24. Adding one space to each of the six short rows fixes it.
✅ What I verified
- Head
b57f989.cargo test --test shell_integration: 1634 passed.human_size_matches_gnupasses.cargo fmt --checkis clean, andcargo clippy --workspace --all-targetsreports no warnings inls.rs. - Compared with GNU coreutils 9.1 on a direct bind, using explicit operands, mixed files and directories,
-t/-tr/-S/-Sr/-r,-ta/-Sa/-Rt/-RSr/-ltr/-lhS, and a nonexistent operand. With symlinks removed, every case orders the same as GNU. Where-llines differ, it's only the nlink/owner columns we don't print, which was already the case on main. The remaining order differences are symlinks being sorted by their target (#254). - I re-ran the in-memory VFS repro from my earlier review.
-t,-trandhead -1are now correct. - Evidence uploaded:
followup-operand-sort-gnu-diff.log.
|
Thanks for checking the operand cases. You are right, I missed the remaining one-column difference in the help text. I am leaving that cosmetic nit for a follow-up so this approved revision can finish its CI run without restarting the matrix. |
Description
Human-readable listings printed help instead of files, and sorting by time or size was rejected. Those are commands agents use to inspect file sizes and pick the newest or largest file.
This changes
lsand its tests to add human-readable sizes and time, size and reverse sorting for both directory contents and file operands, including files expanded from a glob. Files are listed before directories, and adjacent file operands no longer get blank lines between them. Direct-bind symlink metadata (#254) and glob expansion on direct binds remain separate issues.I compared 28 cases with GNU ls covering file operands, mixed directories, recursive sorting, complete long-listing rows and globs. The new operand regressions failed before the fix and pass now, and the full Rust suite, lint, doctests and documentation checks pass.
Related Issues
Part of #207
Documentation PR
N/A
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.