Skip to content

fix(find): POSIX drive-form start points; test: grep symlink SKIP degradation, tput stdin-preservation contract (#1170 #1168 #1166) - #1171

Merged
caomengxuan666 merged 3 commits into
mainfrom
fix/1166-1168-1170
Oct 12, 2026
Merged

caomengxuan666 merged 3 commits into
mainfrom
fix/1166-1168-1170

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1170, fixes #1168, fixes #1166. Three independent tickets, one branch, one commit each.

#1170 — find: POSIX drive-form start points (/c/..., /d/...)

Root cause. find was the last tool-layer exception to boundary contract B2: other tools route path operands through winux::native_path::normalize_api_operand, but find's start-point operands went straight from argv into std::filesystem, so /c/... never resolved (its -exec child lookup was already unified by #1169).

Fix. Route every start point through the shared operand helper: command-line roots (parse_roots), -files0-from entries, and the -files0-from source operand. Native/relative forms pass through unchanged; /c/..., /d/..., /cygdrive/c/... fold to native spellings, matching msys find semantics.

Evidence.

  • GNU attestation: findutils 4.9.0 under WSL accepts POSIX absolute start points verbatim (rc=0).
  • RED (before): find /c/Windows/System32/attrib.exe -maxdepth 0 → rc=1 "No such file or directory", same as the issue's repro against 1.1.5.
  • GREEN: new find.find_accepts_posix_drive_form_start_points covers a /c/... directory root, a /c/... regular-file root (-maxdepth 0), and traversal below a POSIX root. find.* 117/117, childproc.* 17/17.

#1168 — grep tests: symlink privilege degradation

Root cause. grep_r_skips_cross_junction_trees_without_crashing (:1562) and grep_R_warns_and_terminates_on_junction_cycle (:1591) called the throwing std::filesystem::create_directory_symlink; on non-admin hosts without Developer Mode it throws Win32 error 1314 and the exists() fallback was unreachable.

Fix. Mirror the create_directory_symlink_or_skip helper every other unit test file carries (ls/readlink/touch/unlink/find): raw CreateSymbolicLinkW + SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE, printing SKIPPED (CreateSymbolicLinkW failed with error 1314) and returning early.

Evidence. Non-admin host: both cases FAILed before, now SKIPPED (error 1314) / PASSED. Full suite: 2836/2836 passed, 0 failed (ctest -C Debug, this host is non-admin — the two legacy reds are gone).

#1166 — tput: stdin preservation on the failure path

Analysis. GNU tput never consumes stdin (WSL ncurses 6.4 attested, success and failure). At this tree's HEAD, tput.cpp is byte-identical to v1.1.5 — a fixed capability table with no terminfo lookup — and no shared startup layer (main/console/pager/dispatcher) reads stdin. In a pure-Win32 cleanroom (pipe stdin, write end held open until child exit, leftover measured via PeekNamedPipe), the failure path (tput lines → rc=1), the success path (tput clear → rc=0), and the missing-operand path all leave piped aq fully intact. The drain reported against the NiuBash 1.4.0 bundle could not be reproduced from this tree; its terminfo-driven failure path does not exist here.

Deliverable (the differential test the issue asks for): Pipeline::probe_stdin_leftover() (opt-in framework mode: keeps the stdin write end open until the child exits, reports unconsumed bytes as CommandResult::stdin_leftover) plus three tput tests pinning that success, unknown-capability and missing-operand paths preserve stdin — any future stdin read on any tput path now fails the suite.

Checklist

  • RED captured before each fix (find POSIX roots rc=1 x3 scenarios; grep 1314 unhandled-exception FAILs)
  • Full build via scripts/build-with-vs.ps1 in the PR worktree; full ctest: 2836/2836 passed
  • clang-format --style=file clean on all touched files
  • CHANGELOG updated under Unreleased → Fixed
  • I18N review: no user-visible text changed (diagnostics reused verbatim, comments/tests only) — no winuxcmd-i18n catalog change required
  • Cross-repo note for find: POSIX 形态起点路径(/c/...、/d/...)报 No such file or directory #1170: once merged, rubash's tests/path_contract_boundary_posix_forms.rs::winuxcmd_tools_accept_posix_operands can switch find's unit from the . relative start point to a /c/... POSIX form, per the audit comment

…nd boundary (#1170)

find was the only tool-layer exception to the boundary contract B2 audit:
touch/ls/env/timeout/xargs/rm all accept explicit POSIX path operands, but
find's start-point operands went straight into std::filesystem, so
"find /c/Windows/System32/attrib.exe -maxdepth 0" failed with
"No such file or directory" while the native "C:/..." spelling worked
(-exec child lookup was already unified by #1169).

Route every start point through winux::native_path::normalize_api_operand,
the same helper the other tools use for their operands: command-line roots
(parse_roots), -files0-from entries, and the -files0-from source operand.
Native and relative forms pass through unchanged; POSIX drive forms
(/c/..., /d/..., /cygdrive/c/...) fold to their native spellings.

GNU attestation: findutils 4.9.0 under WSL takes POSIX absolute start
points verbatim (rc=0). RED->GREEN covered by
find.find_accepts_posix_drive_form_start_points, which drives a /c/...
directory root, a /c/... regular-file root (-maxdepth 0), and traversal
below a POSIX-form root.
)

grep_r_skips_cross_junction_trees_without_crashing and
grep_R_warns_and_terminates_on_junction_cycle called the throwing
std::filesystem::create_directory_symlink directly, so on hosts without
symlink-creation privilege (non-admin, no Developer Mode) both tests died
with an unhandled filesystem_error (Win32 error 1314, "A required privilege
is not held by the client") instead of skipping. The exists() guard after
the call was unreachable because the throwing call never returned.

Add the same create_directory_symlink_or_skip helper the other unit test
files carry (ls/readlink/touch/unlink/find): raw CreateSymbolicLinkW with
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE, printing a SKIPPED line with
the GetLastError() code and returning false on failure. Non-admin full-suite
runs go back to all-green (the 2811-run legacy of 2809 passed / 2 failed).
…aths (#1166)

GNU tput answers capability queries from the terminfo database alone and
never consumes stdin -- success or failure -- so scripts like
"printf 'aq' | { tput lines; IFS= read -rsn1 k; ... }" keep their data.
The issue reports WinuxCmd's tput draining the pipe on the terminfo-less
failure path.

Analysis at this tree's HEAD: tput.cpp is byte-identical to v1.1.5 (47
lines, a fixed capability table, no terminfo lookup) and no shared startup
layer (main/console/pager/dispatcher) reads stdin; in a pure-Win32
cleanroom (CreateProcess with pipe stdin, write end held open until child
exit, leftover measured via PeekNamedPipe) the failure path (unknown
capability, rc=1), the success path (clear, rc=0), and the missing-operand
path all leave the piped "aq" fully intact. The drain reported against the
NiuBash 1.4.0 bundle could not be reproduced from this tree; its terminfo
lookup does not exist here.

Deliverable per the issue's own fix list is the GNU differential test: the
test framework gains an opt-in Pipeline::probe_stdin_leftover mode (keeps
the stdin write end open until the child exits, reports unconsumed bytes
in CommandResult::stdin_leftover), and three tput tests pin the contract
so any future stdin read on any tput path fails the suite. WSL ncurses
6.4 attestation: GNU tput preserves the pipe on success and failure.
@caomengxuan666
caomengxuan666 merged commit d4210c7 into main Oct 12, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1166-1168-1170 branch October 13, 2026 02:09
caomengxuan666 added a commit that referenced this pull request Oct 13, 2026
…u/sed, CHANGELOG #1167/#1169 (#1178)

* fix(seq): batch stdout into 64 KiB chunks + integral to_chars fast path (issue #1173)

safePrint issues one WriteFile per call, so per-line emission paid a kernel
transition two-three times per line (~30us/line piped; 100k lines ~332ms
while GNU needs ~5ms). Lines now assemble into a 64 KiB buffer flushed in
large chunks, integral first/increment sequences (default fixed format,
precision 0, no --format/-w, |operands| <= 2^52) emit through std::to_chars
like GNU seq.c's integer bypass, and the floating path drops the per-line
size-query snprintf round trip.

100k lines, release build: seq 332ms -> ~45ms, seq | wc 903ms -> ~45ms
(GNU/WSL oracle: 7-10ms; residual is the ~40ms Windows process spawn).
Byte stream unchanged: new seq_large_range_buffered_output_matches_gnu_bytes
pins 588895 bytes/100000 lines across several flush rounds.

* fix(du,sed): POSIX drive-form operands resolve through the shared boundary (issue #1174)

du rejected '/d/...' operands with ENOENT while accepting 'D:/...' and sed
could not read them either — the L2 self-parse contract (tools resolve POSIX
operands themselves) was unevenly applied. Both now route operands through
native_path::make_api_path_operand_w/normalize_api_operand, the same
boundary grep/wc/head/find already use:

- du: traversal operands (and -X exclude files, --files0-from sources) fold
  '/d/src', '/cygdrive/d/src' and /dev pseudo-paths to their Win32 form;
  operand line and child entries agree on the resolved forward-slashed
  spelling (Savannah #13956) while the #1159 trailing-separator collapse and
  error messages keep the operand text as typed.
- sed: input operands (glob patterns included) fold before expansion/open,
  and with -i the folded path is what gets replaced; -f script files and the
  r/w/W script-embedded paths resolve the same way. Diagnostics and the
  '='/F filename display keep the operand text as typed.

GNU oracle (WSL coreutils): du -sh /usr -> '8.5G /usr' rc=0. New tests cover
the dual forms: du -sh '/d/...' vs 'D:/...', sed -n 1p, sed -i and sed -f
through '/d/...' paths.

* docs(changelog): record the #1167 ntfs-noise docs round and #1169 spawn resolver in [Unreleased] (issue #1175)

#1169 (GNU execvp-style child resolution: PATH-only bare-name search with no
cwd/System32 shadowing, POSIX PATH spellings normalized) and #1167 (touch
NTFS literal-glob platform deviation documented, test exemption registered)
were merged without a CHANGELOG entry. PR #1171's own fixes (#1170/#1168/
#1166) were already recorded at merge time (d4210c7), so no duplicate entry
is added for it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant