Repository navigation
fix(find): report a missing path like find does, and disclose hidden/gitignored matches - #3854
Merged
Merged
Conversation
…gitignored matches `rtk find /tmp/nope` exited 0 with no output where `find` prints `find: '/tmp/nope': No such file or directory` and exits 1. The dispatcher read a nonexistent path as RTK name-pattern syntax (`!is_dir()` is true for both), rewrote it to `-name /tmp/nope`, defaulted the search root to `.`, and the existence guard then checked `.` instead of the argument. A token with a path separator can never be a `-name` pattern (`-name` matches basenames), so treat it as a path whether or not it exists; find's own status then surfaces. `run`, `run_compress`, `run_verbatim` and `run_from_args` return the status instead of calling `process::exit`, and the `Find` arm in main.rs yields it. The native walk skips hidden and gitignored entries, so `rtk find . -name secret.txt` printed nothing for a gitignored file and exited 0 — an existence check reads that as "not on disk". The output now ends with `... (N filtered: hidden or gitignored; dirs listed with / were not searched)` plus a tee file listing them, the shape `rtk ls` already uses, and says so even when nothing else matched. The note rides on both sides of the never-worse guard, since the raw listing never holds filtered entries and would otherwise win on size and drop it. The disclosure is derived from the walk that already happened: for each directory the filtered walk visited, its raw children are listed and any child the walk did not visit was hidden or ignored. Skipped files are named when they match; a skipped directory is reported once as `dir/` and never descended. Cost is one read_dir per visited directory: on ext4, a 116-directory checkout with 3000 gitignored files measures 12-14 ms against 14-21 ms before. (Re-walking with the filters off to count matches inside ignored trees took 7.5 s against 350 ms on the same checkout, which is why it is not done.) On a Windows mount under WSL each read_dir is a 9P round-trip, so the disclosure adds roughly 2 ms per visited directory there. Bare names without a separator keep RTK's pattern semantics (`rtk find Cargo.toml`); a pattern starting with `.` still walks hidden entries. Fixes #3851
aeppling
force-pushed
the
fix/find-exit-code-and-hiddens
branch
from
September 3, 2026 17:22
b6b93ce to
765b270
Compare
… root, align the note with ls Review follow-ups on the disclosure added for #3851. - The walk kept every visited path in a set for the whole run, so on a 108k-entry tree RSS went from 7 MB to 18 MB and the extra read_dir pass doubled the time. Disclosure now switches off once 20 000 entries have been visited and the bookkeeping is dropped; below that nothing changes. Measured on /usr: 3.9-4.0 s and 9.6 MB against develop's 3.9-7.0 s and 6.9 MB. - A symlinked search root reported its file type as a symlink, so it never counted as a visited directory and its filtered children went unreported. The root's type is now read through the link. - The note is `... (N filtered)`, the same shape rtk ls emits; the trailing `/` on a reported directory already says it was not searched. - `.git` comes from a named constant instead of an inline literal. - The fixture test disables global gitignore rules so a developer's own excludes cannot change its result; two tests point RTK_TEE_DIR at a tempdir instead of writing under ~/.local/share/rtk. - find_cmd.rs is included through automod, which cargo fmt does not see; the file is now rustfmt-clean when checked directly.
pszymkowiak
approved these changes
Sep 3, 2026
Merged
This was referenced Sep 7, 2026
This was referenced Sep 19, 2026
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3851
Summary
rtk find <missing-path>exited 0 with no output: a nonexistent path was read as RTK name-pattern syntax and searched from.. Hidden and gitignored matches were also dropped silently, so an empty result looked like "not on disk".Changes
find's own status (No such file or directory, exit 1) now surfaces. Bare names keep RTK pattern syntax.find_cmdreturns the exit status instead of callingprocess::exit; theFindarm inmain.rsyields it.... (N filtered: hidden or gitignored; …)plus a tee file, derived from the directories the walk already visited — skipped files named, skipped directories reported once asdir/, never descended.Test
cargo test3135 passed; fmt and clippy clean.find: missing path → 1 + stderr on every route; gitignored existence check → disclosure note; 12 ordinary usages identical todevelopapart from the note.