Repository navigation
fix(ls): hold a bare listing to what ls prints, not to the long listing rtk asks for - #4833
Conversation
…ng rtk asks for rtk ls asks its child for a long listing to learn each entry's type and size, and printed that size after every file even when the user never passed -l. Without -l, ls prints bare names, so the size column was pure addition: in rtk's own repository root `ls` prints 341 bytes and `rtk ls` printed 531. The never-worse guard could not catch it. The runner compares the filtered output with the child's stdout, and that stdout is the long listing rtk asked for (2067 bytes), not the listing the user did. A listing without -l now prints names only, and is held to the output of `ls` run with the user's own arguments: the compact form is shown only when the shared never_worse finds it cheaper than that output. The same baseline governs the two places the filter used to print the long listing verbatim: a listing it cannot parse (-T and -D dates, the attribute lines of -@ and -e), and a failed run, where `ls src missing` printed 742 bytes of long listing for the 108 bytes ls printed. A long listing keeps its existing filter and baseline. The baseline costs one more `ls` process for a listing without -l.
📊 Automated PR Analysis
SummaryFixes rtk's Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
…ejected command into an empty success A listing with -l is now held, like a bare one, to the output of ls run with the user's own arguments. When ls rejects the command line outright (non-zero exit, nothing on stdout) while rtk's listing succeeds, there is no listing to hold to, so rtk lists as before instead of printing nothing with exit 0.
|
@aeppling thanks for the thorough write-up and the differential fuzzing. The direction is right: a bare
Once these are settled I am happy to re-review. |
…hrough on its own a_tools_own_dash_h_is_still_filtered runs `ls -h` again, on a directory of 60 files where the compact form wins, so it still proves rtk filters a listing that carries -h. The two-file directory, where rtk now prints exactly what `ls -h` prints, gets its own test.
|
@pszymkowiak thanks for the review. Not accurate: locale (1). The byte count does change with the locale: Fixed: Measured: |
pszymkowiak
left a comment
There was a problem hiding this comment.
@aeppling you're right on the locale, I checked: ls -b with café.txt is 16 B in UTF-8 vs 22 B in C, and rtk ls -b returns the 16. Keep it as is. The -h test split looks good, and the ls unit tests, ls_never_worse_test and help_passthrough_fuzz_test all pass on db26b75.
On the -l cost, I measured on release builds: ls -lR src 9 → 12.4 ms, ls -la 6.6 → 8.4 ms. Not blocking, but spawning the baseline ls before the filtered one and waiting on it afterwards would run both in parallel and bring it back to the slower of the two.
Approving. The only thing left before merge is the CLA: the commits use [email protected], which isn't linked to your GitHub account.
Summary
rtk lswithout-lprinted a size after every file (kubectl 57.9M), which plainlsnever prints: barertk lscost more thanlsitself (341 → 531 bytes in this repo's root).ls -lrtk injects (2067 bytes), not thelsthe user typed (341 bytes).-l, is now held through the sharednever_worseto the output oflsrun with the user's own arguments. A listing without-lprints names only. The same baseline replaces the two places the filter printed the long listing verbatim: an unparsable listing (-T/-Ddates,-@/-eattribute lines) and a failed run (ls src missingprinted 742 bytes of long listing for the 108 byteslsprinted).lsrejects the command line outright (non-zero exit, nothing on stdout, e.g. GNU--allon macOS) while rtk's own listing succeeds, there is no listing to hold to: rtk lists as master does, instead of printing nothing with exit 0.Cost: one extra
lsprocess per call.rtk ls -la8.9 → 12.3 ms mean (+2.4 ms CPU) on macOS with hyperfine; barertk ls+≈2.6 ms CPU.Before / after (bytes, rtk repo root, macOS)
lslsls -als srcls -tls -Fls src missing(exit 1)ls src -l(BSD reads-las a file)ls --all src(BSD rejects--all, exit 1)ls -lls -lals -lRLarge directories still compact (cap + noise dirs + recall hint) whenever that is cheaper than
ls.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test --all --no-fail-fast: 56 test binaries, 5266 passed, 0 failed; proxy fmt cleanrender: falls back to native output when/markers or the hint cost more, keeps the compact form when it saves, exhaustive dir/file/noise combinations never exceed native, unparsable dates and failed listings held to native, long listings held to native and compact when cheapertests/ls_never_worse_test.rs: nativelsvsrtk lsin temp directories, byte-identical where compacting costs more, never larger across-a -A -1 -F -p -d -R -l -la -lh -ltr, multi-operand, empty dir, failed runs keep exit code, stderr and native stdout, unreadable directory prints whatlsprinted, flags after an operand held to whatlslisted, optionslsrejects never become an empty successhelp_passthrough_fuzz_test: thelscase ofa_tools_own_dash_h_is_still_filterednow uses-l -h(a two-file bare listing is correctly passed through as native output now; the-htoken is still exercised)ls: 76,945 cases (every BSD short flag,-Dwith a value,--colorforms and every GNU long option, all flag pairs in separate/clustered/reversed form, 40k seeded random 2–6 flag clusters with operand mixes, flags moved after operands) over six fixtures (empty, home-like, repo with noise dirs, >50 entries, odd names incl. leading dash, trailing dots,->, tab/newline, symlinks, FIFO, setuid, unreadable dir, empty multi-operand). Each case ran nativels, master and this PR, with every recall hint expanded before judging information loss.lsls-l)lslsfailedAll 554 cases still larger than
lsare command lines BSDlsrejects (unrecognized optionfor a GNU long option: exit 1, nothing on stdout), which rtk lists as master does. Whereverlsprinted a listing,rtk lswas never larger. The other remaining cases are unchanged from master and outside this fix: exit codes for flags after an operand and GNU options on BSD,-i/-scolumns dropped when the compact form wins, names ending in.(#4305), symlink-to-directory operands (#3649), and empty directories listed with a flag after the operand.Not run: GNU
lson Linux (Docker unavailable locally); CI covers the integration tests there.Related: #561, #4026, #4051, #3075, #4041.