Repository navigation
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe glob walker now matches absolute literal patterns and final literal components through stat operations. Tests cover match results, path errors, and behavior in bundler, workspace, and shell flows. ChangesAbsolute literal glob matching
Suggested reviewers: Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to
|
|
Updated 7:05 AM PT - Oct 16th, 2026
❌ @robobun, your commit 8f6c026 has 1 failures in 🧪 To try this PR locally: bunx bun-pr 34989That installs a local version of the PR into your bun-34989 --bun |
|
Found 1 issue this PR may fix:
🤖 Generated with Claude Code |
There was a problem hiding this comment.
The stat() rewrite resolves both earlier 🔴 findings: /etc/passwd/foo now hits stat → ENOTDIR → [], and Windows no longer depends on the libuv-dropped O_DIRECTORY flag. Also checked the trailing-separator-on-a-file case — on POSIX stat("…/file/") returns ENOTDIR so it correctly yields []; the inline nit suggests pinning that with a test.
Extended reasoning...
The follow-up commit c8a61ab replaces the open(O_DIRECTORY) probe with A::stat() and branches on S::ISREG(mode) || !only_files, which addresses both prior blockers (non-existent-prefix ENOTDIR now goes to GetNext; Windows classification no longer relies on a flag libuv discards). The only remaining finding is a test-coverage nit on the ENOTDIR arm — the two negative cases my earlier review named (path.join(file, "nope") and file + path.sep) still aren't asserted, so that clause is unpinned. Not approving on that basis alone, but the substantive correctness concerns from the previous round are resolved.
c8a61ab to
5b0e97a
Compare
|
This PR is rebased on main (e4c638f), after #44968 and #45043 merged.
Reproduction: The tests of this PR passed on the Windows and macOS lanes before the rebase (171082f). |
There was a problem hiding this comment.
I re-reviewed after 171082f and found no bugs; the two test rows from my earlier note are gone. Because this rewrites the only path that produces a literal match in the shared glob walker (Bun.Glob, the shell, bun run --filter, compiled executables) with Windows branches I cannot execute here, a human look is still worthwhile.
What was reviewed:
- The new "statat may receive EMPTY" contract against all three Accessor impls: POSIX
fstatatmaps an invalid fd to AT_FDCWD,statat_windowsgets the earlySyscall::stat, and StandaloneAccessor/DirEntryAccessor already pass an absolute path through untouched. - fd release in the literal-tail path:
close_disallowing_cwdnow runs aftermatch_literalon both outcomes; the?sites inside it (join,prepare_matched_path) cannot return Err in practice, so no new leak path. prepare_matched_path(name, b"")for the absolute branch:join_sep_vecskips empty parts, so no doubled separator; theabsolute: trueoption now routes the literal through the normalizing join like every other match.- Trailing-separator strip stops at the root on both platforms (
windows_filesystem_root(..).len().max(1)/ 1), and the "filesystem root" test pins/andC:\returning themselves.
Extended reasoning...
The diff rewrites the absolute-literal and literal-tail paths in src/glob/GlobWalker.rs into a single match_literal method (stat-based, ENOENT/ENOTDIR mapping differs per Literal arm), adds NUL to the glob-syntax byte sets, deletes dupe_matched, and adds tests across scan.test.ts, filter-workspace, compile-asset-bunfs and bunshell. It touches no auth, crypto or injection surface; the sensitive part is filesystem probing semantics shared by several Bun subsystems. The bug hunt ran dry with no findings, no third-party objections are outstanding, and the latest commit removed the rows my prior nit flagged. I deferred rather than approved because the change alters user-visible glob semantics in a core walker with cfg-gated Windows code that cannot be exercised in this environment.
`Iterator::init` answered an absolute pattern with no glob syntax from the errno of a directory open, and set `IterState::Matched` without `prepare_matched_path`. `Glob.scan()` and `scanSync()` read their result from `matched_paths`, so the match was lost. The same branch ignored `onlyFiles`, matched `<file>/child`, and on Windows could not tell a file from a directory. `Iterator::match_literal` is now the only place that sets `IterState::Matched`. It stats the name, classifies it, and records it through `prepare_matched_path`. The absolute branch calls it with `AccessorHandle::EMPTY` and `Literal::Pattern`: ENOENT and ENOTDIR are no match, `onlyFiles` applies, and a trailing separator needs a directory. `statat_windows` stats the path as given for an invalid handle. The literal tail of `transition_to_dir_iter_state` calls it with `Literal::LastComponent` and keeps its rule and its error path. A component with a NUL byte is no longer classified as `Literal`, so it never becomes a C string that names another path. `walk()` asserts that every path it is given is in `matched_paths`. `dupe_matched` has no caller left and is removed.
171082f to
8f6c026
Compare
There was a problem hiding this comment.
I reviewed this push and didn't find any bugs; it addresses what I raised on the earlier versions (classification now comes from a stat instead of the errno of an O_DIRECTORY open, the ENOTDIR rows are covered by underFile/fileTrailingSepAll/missingParent, and the literal-tail test no longer pins a.js/ matching a file). Because it reworks the one path that all three Accessor implementations share and includes Windows-only code that cannot be built here, a human look would still be worthwhile.
What was reviewed:
match_literal(Literal::LastComponent)against the removed literal-tail block: sameISREG || !onlyFilesrule, same ENOENT-only silence, same joined error path;close_disallowing_cwd(fd)now also runs on the join/prepare alloc-error exits, which the old block skipped.A::Handle::EMPTYintostatatfor each accessor:SyscallAccessormaps an invalid fd toAT_FDCWD(and toSyscall::staton Windows),DirEntryAccessorandStandaloneAccessorpass an absolute path through untouched.- Trailing-separator strip and root guard for
/,C:\, a POSIX-style rooted path on Windows, anddir//;joinskips the emptydir_path, so the result is the pattern as written minus the separator. - NUL in
SYNTAX_TOKENS: such a component is neverLiteral, sodupe_znever builds a C string from it and thedebug_assertinmatch_literalholds.
Extended reasoning...
The change rewrites the two literal fast paths in src/glob/GlobWalker.rs (absolute pattern with no glob syntax, and a literal last component) into one match_literal that stats the path, classifies by S_ISREG/S_ISDIR with onlyFiles and a trailing-separator rule, and records the hit through prepare_matched_path, which is what makes scan()/scanSync() return absolute literal matches; it also adds NUL to the syntax tokens and the Windows NT name filter. It touches no security-sensitive surface beyond path handling, and the NUL change tightens C-string construction. All of my earlier inline findings are addressed in this commit and the added tests pin the absolute rules, the error paths, and the standalone/--filter consumers. Deferring rather than approving because the walker is shared by three accessors across platforms and the Windows-gated branch cannot be type-checked in this environment.
|
Closing as stale: this PR conflicts with main, and its last commit is from 2026-10-16. The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR. |
Fixes #16709
Problem
new Bun.Glob("/abs/file.js").scanSync()and.scan()return[]for an existing path (absolute pattern, no glob syntax). A regression from Glob support for workspace names in bun install #10462 (1.1.7).Iterator::init(src/glob/GlobWalker.rs:425) reads the errno of a directory open and skipsprepare_matched_path. Somatched_paths(thescan()result) stays empty.bun run --filterfails (error: Unexpected) for an absoluteworkspacesentry.Fix
Iterator::match_literalsetsIterState::Matched: oneAccessor::statat(empty handle for the absolute branch), thenprepare_matched_path. No accessor changes.onlyFilesapplies, a trailing separator needs a directory.walk()asserts each path is recorded.test/js/bun/glob/scan.test.ts(7 tests fail on main). Self-reviewed: 16 concerns raised, 16 addressed.Background
Accessor: filesystem, resolver cache (bun run --filter), compiled-executable files.packages/*/package.json) takes one stat per directory, no directory read.Accessor::stat(the first version): it broke the build on main's third accessor.Downsides
a.js/matches a file (glob: keep the trailing separator out of the last pattern component #34200), a literal link through a file throws ENOTDIR. The absolute forms return[].fstatat(wasopen). An unreadable directory now matches (was EACCES)..text: -5,376 bytes. Measured before the rebase (7c96a12).Notes
Reproduction
The regression
#10462 (303f86a, in 1.1.7 and not in 1.1.6) made
matched_pathsthe result ofscan()and moved the insert intoprepareMatchedPath*.walk()had appended every path the iterator gave it. The two sites that set.matchedfor an absolute literal pattern never calledprepareMatchedPath, so their match was dropped from then on. This is from the history. No old release was run.What changes
match_literal(Literal::Pattern, ..), for an absolute pattern with no glob syntax:onlyFiles: false), the rulematch_pattern_fileapplies to wildcards. The match is returned without the separator./andC:\keep theirs. The strip uses the parser's separator test, so a\in a name on POSIX stays in the name.onlyFiles: false.match_literal(Literal::LastComponent, ..), for the literal tail, keeps what main does:ISREG || !onlyFiles, no trailing separator test, only ENOENT is silent, and a thrown error carries the path from the cwd (packages/a/package.json, from #44968).A name with a NUL byte is never classified as a literal (
SYNTAX_TOKENS), so it is only compared with directory entries and never becomes a C string.a.js\0junkreturned itself after a stat ofa.js, and<dir>\0junk/*.txtreturned a path that was never probed. Both return[]now. A debug build of main stops on the relative form withZStr::as_cstr: interior NUL would truncate the C view(a debug assertion). No test pins this: #33181 rejects a NUL in the pattern and incwdwithERR_INVALID_ARG_VALUE, and that PR owns the answer. A NUL incwdis unchanged here. On Windows the NT name filter now rejects a NUL as well, so such a name does not reachNtQueryDirectoryFile.Rows (75 rows on the unfixed 1.4.3-canary and on this branch before the rebase,
scanSyncandscan, Linux)[]to the match. None goes from[]to a throw. Error rows report syscallfstatatwhere they reportedopen(staton Windows).onlyFilesstates.onlyFiles: falsethrew EACCES. It now matches, as the relative form does (run as uidnobody)./dev/nullnamed by an absolute literal pattern matches only withonlyFiles: false.Measurements (Linux x64, release builds from one build directory that differ only in
GlobWalker.rs, on main 7c96a12. Not measured again after the rebase onto e4c638f: the rebase did not change this diff on the measured paths.)gdbcatch syscall). Each is onenewfstatat(AT_FDCWD, <pattern>).<D>/*.js6,<D>/./a.js5,pkgs/*/package.json3 per package directory (was 3 / 6 / 5 / 3). The syscall logs of the two builds differ in 0 lines.transition_to_dir_iter_statecall, counted withgdbstepi.perf,valgrind,straceandbloatyare not installed in the build container, and it has no network to install them. A call that sets up a directory read and reaches no literal: 289 on main, 293 here (+4). A literal-tail hit for onepkgs/*directory: 1,475 on main, 1,416 here (-59). A relative literal match (Iterator::init): 1,405 on main, 1,337 here.GlobWalker::init_with_cwd, once per scan):pkgs/*/package.json1,046 instructions on main, 1,061 here./tmp/measure/D/a.js: 1,181 on main, 1,194 here.gdbbreakpoints on the mimalloc entry points): literal tail per directory 4 (was 5). Relative literal match 7 (was 8), miss 3 (was 4). Absolute literal match 5, miss 2 (was 3 and 3, and the match was dropped)..text-5,376 bytes (size -A), walker symbols -2,310 bytes (nm -S).IterState::Matched1 (was 3).matched_paths.insertsites 3 (was 3).Accessorfunctions 5 (was 5). Accessor implementations touched: 0.Not in this PR
a.js/on a regular file and a literal symlink whose target crosses a regular file keep main's relative results (["a.js"]and a thrown ENOTDIR). The absolute forms return[]. Each is one arm ofLiteralto flip. glob: keep the trailing separator out of the last pattern component #34200 owns the trailing separator, with**/a.js/, which this PR does not touch.echo */x.txt: 6 of 35 matches on main and here). Unchanged.<abs>/nope/*.js) still throws ENOENT where the relative form returns[].bun run --workspaceswith<abs>/nope/*still printserror: FileNotFound. This PR fixes the--filtersymptom only for an entry with no glob syntax. bun run --filter: accept an absolute workspaces entry without glob syntax #43362 changesDirEntryAccessor::openatfor that symptom and is not replaced: its accessor change also reaches the walker's other errno checks.Iterator::nextstill reads ENOTDIR from a directory open as "the target is a file":Glob("**/a/link")returns a link whose target does not exist.**, never return a device, a FIFO or a socket (Bun's Glob.scan and fs.glob do not detect unix domain sockets #17506).a \(1\).js) are glob: honour backslash escapes of non-special characters in scan() #32876. A pattern that ends in/.returns[].Suites run (debug build, Linux x64)
test/js/bun/glob/scan.test.ts: 211 pass, 3 skip, 6 fail. The six are theglob.matchrecursive searches, which time out at 30 s in the build container without this change as well.test/bundler/compile-asset-bunfs.test.ts9 pass.test/cli/run/filter-workspace.test.ts126 pass.test/js/bun/shell/bunshell.test.ts451 pass.test/js/bun/shell/brace.test.ts47 pass.test/js/node/fs/glob.test.ts34 pass.test/cli/run/workspaces.test.ts4 pass.test/cli/install/bun-workspaces.test.ts288 pass.test/cli/install/bun-workspaces-self-contained.test.ts25 pass.test/js/bun/glob/match.test.ts: 569 pass, 5 fail in a whole-file run (thedot segmentstests startbun lintand time out at 5 s under load). All 8 pass when run alone.GlobWalker.rs), pass here: sevenscan.test.tstests (the absolute rows, the name table, the bracket comparison, the root, the device node, the absolute symlink rows, the error rows), theabsoluteLiteralFileandabsoluteLiteralDirrows ofcompile-asset-bunfs.test.ts, andabsolute workspace path without glob syntaxinfilter-workspace.test.ts(from bun run --filter: accept an absolute workspaces entry without glob syntax #43362,error: Unexpectedon main).literal last component(two tests), the relative symlink rows, the tail's error path (after a wildcard, names the path from the cwd), andA literal name after a wildcardinbunshell.test.ts, which covers the shell's copy of the tail. Main'sa failed stat reports the path from cwdskips as root. A probe with its two assertions passes here as uidnobody. No test assertsa.js/on a regular file for the tail: glob: keep the trailing separator out of the last pattern component #34200 decides that row.cargo check -p bun_globpasses forx86_64-pc-windows-msvcandaarch64-apple-darwinafter the rebase (bun run rust:check-allpassed for both Windows targets andaarch64-apple-darwinbefore it).no test proof · iteration 2 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/js/bun/shell/bunshell.test.ts, test/js/bun/glob/scan.test.ts, test/cli/run/filter-workspace.test.ts, test/bundler/compile-asset-bunfs.test.ts