Skip to content

fix(builtins): bare builtin applies its redirections (rubash#1643) - #1682

Closed
arookieofc wants to merge 1 commit into
masterfrom
fix-1643-bare-builtin-redir
Closed

arookieofc wants to merge 1 commit into
masterfrom
fix-1643-bare-builtin-redir

Conversation

@arookieofc

Copy link
Copy Markdown
Member

Fixes #1643.

GNU execute_builtin applies a simple command's redirections before the builtin runs, even when the builtin takes no arguments. The bare-builtin early return in execute_builtin_direct_command skipped that pass entirely, so builtin > f created no file and builtin > f on an existing file did not truncate it — while command and : take their own redirect passes and agreed with GNU.

The early return now applies the same no-output-builtin redirect pass the : arm uses (in/out/append/err), with the same status rule: failed redirect -> 1, otherwise 0.

Verification (local, master 499a5e2 + this fix, vs GNU):

  • builtin > f creates f, builtin >> f creates f, builtin 2> e creates e, existing file truncated to 0 — all matching GNU.
  • builtin < /dev/null rc 0 and builtin echo HI > f unchanged; failing redirect reports the target and rc 1, matching GNU; builtin -- > f also creates f.
  • New regression file tests/issue1643_bare_builtin_redirect_regressions.rs: 5/5 passed; issue1412 builtin-exec-redirect suite still passes.

GNU execute_builtin applies a simple command's redirections
before the builtin runs, even when the builtin takes no
arguments. The bare-'builtin' early return in
execute_builtin_direct_command skipped that pass entirely, so
'builtin > f' created no file and 'builtin > f' on an existing
file did not truncate it — while 'command' and ':' take their
own redirect passes and agreed with GNU.

The early return now applies the same no-output-builtin
redirect pass the ':' arm uses (in/out/append/err), with the
same status rule: failed redirect -> 1, otherwise 0.

Regression tests:
tests/issue1643_bare_builtin_redirect_regressions.rs (5 tests:
create, append + stderr targets, truncate, failed redirect
rc=1 with diagnostic, '--' form and plain no-op).
@caomengxuan666

Copy link
Copy Markdown
Member

Closing as incorporated per the 2026-10-26 fd-source dual-route ruling (recorded in DECISIONS.md; full comparison in the collab PR review report §3.1/§4.3).

The slice PR #1689 was chosen as the single landing route for #1643 and has merged (merge commit 9355be310c9fbb164992ce028006deb982bb7861). For this PR specifically:

  • Production code: no difference. Both sides change the same hunk of src/executor/builtin_direct_command.rs (same base blob), call the same helper apply_no_output_builtin_redirects_with_status, and apply an equivalent failure→1 / success→0 status rule — the two versions differ only in spelling (if redirect_failed {1} else {0} vs i32::from(redirect_failed)).
  • Tests: this PR's 5 cases are a subset of the slice's (8 active cases with finer splits plus a named-builtin control, and an additional #[ignore] pin for the adjacent numbered-fd gap, filed as numbered fd redirections (3>) are not performed for bare builtin and : (shared no-output redirect helper skips numbered entries) #1687).
  • This PR has no unique production content and no unique test shapes — nothing is lost by closing it unmerged. The two routes conflict textually on the same hunk, so they cannot both land.

Thanks for the contribution — it independently reached the same fix and served as the cross-check for the ruling.

@caomengxuan666
caomengxuan666 deleted the fix-1643-bare-builtin-redir branch October 30, 2026 01:41
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.

[bug] bare builtin with redir-only ignores output redirections (GNU performs them)

2 participants