Skip to content

fix(find): let --help/--version act where the expression parser reaches them (Refs #1633) - #1658

Closed
caomengxuan666 wants to merge 2 commits into
mainfrom
fix/1633-find-help-version
Closed

caomengxuan666 wants to merge 2 commits into
mainfrom
fix/1633-find-help-version

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

修了什么

GNU findutils 把 --help/--version 注册在谓词表里、按表达式顺序解析:未知谓词在前先报错;被别的谓词吃作操作数(-name -help)或在 -exec 体内的拼法不触发。现行 act-immediately 预扫描在解析前全 argv 扫一遍,不管位置都打印 help/version:find . -foo --version 打印 version、rc 0,GNU 是 unknown predicate '-foo'、rc 1。

本 PR 把处理挪进表达式解析器:-help/--help、-version/--version 成为 primary,解析器遇到第一个就记入 Config::immediate_action 并停解析,后面的 token 不再被判定;-context 保留 SELinux 拒绝文案,现只在谓词位置触发。删掉原预扫描循环。分发器从不拦截 find 的 --help/--version(find 的 allow_long_options 为 off),解析器是唯一路径。

回归钉

tests/unit/find/find_unit_test.cpp 新增 9 格(每格的 GNU 行为均以本地 findutils 4.9.0 实测为准):unknown_predicate_before_version_errors、version_before_unknown_predicate_prints、unknown_predicate_before_help_errors、help_before_unknown_predicate_prints、name_operand_help_is_pattern、help_after_or_acts、version_in_parens_acts、context_after_unknown_predicate_errors_first、context_rejected。

未改动

验证

…es them (Refs #1633)

GNU findutils registers --help/--version in the predicate table, so
an unknown predicate before them errors first and a token consumed
as another predicate's operand (e.g. -name -help) or inside an -exec
body never triggers them. The shipped act-immediately pre-scan ran
before parsing and printed help/version regardless of position:
find . -foo --version printed the version with rc 0 instead of
reporting the unknown predicate.

Move the handling into the expression parser: -help/--help and
-version/--version are primaries now; the first one reached records
the action in Config::immediate_action and stops the parse, so
nothing after it is judged. -context keeps its SELinux rejection
wording, now reached only in predicate position. The former pre-scan
loop is deleted; the dispatcher never intercepts find's --help /
--version (allow_long_options is off for find), so the parser is the
only path.

Tests: tests/unit/find/find_unit_test.cpp
issue_1633_unknown_predicate_before_version_errors,
issue_1633_version_before_unknown_predicate_prints,
issue_1633_unknown_predicate_before_help_errors,
issue_1633_help_before_unknown_predicate_prints,
issue_1633_name_operand_help_is_pattern,
issue_1633_help_after_or_acts, issue_1633_version_in_parens_acts,
issue_1633_context_after_unknown_predicate_errors_first,
issue_1633_context_rejected (9 new pins, GNU findutils 4.9 probed
for every shape).
…efs #1633)

The two -context pins asserted bare `-context` reaches the expression
parser, but the generic option parser rejects a value-taking -context
with no operand before the handler runs ("option requires an argument
-- 'c'", rc 1; GNU Q1 kind-equivalent "missing argument to
'-context'"). With an operand present the parser does reject -context
with the SELinux diagnostic, so the pins now carry the operand and a
new pin documents the bare form's ctx error.

i18n drift baseline: records the #1633 string move (2 legacy keys) plus
the rust2 tr! batch-1 sync (winuxcmd-i18n 9201a79, 23 keys + 1
placeholder mismatch) that landed after the baseline was recorded.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Superseded by #1696 (find wire handles help/version in the Rust parser).

aphrody-dev pushed a commit to aphrody-labs/WinuxCmd that referenced this pull request Nov 20, 2026
The inventory still called six commands c++-only after their rust2
library/wire landed. Rows now say state=wired, status=rust2-wired,
engine=rust2, with commit evidence in the anchor:

- ls:   unixwin#1762 library 3025942; f87be22 wire (this branch)
- rm:   unixwin#1751 library 38e6835; f14bc60 wire (this branch)
- find: unixwin#1634 library; 792c31f (unixwin#1696 wire); unixwin#1633/unixwin#1658 help/version
- grep: unixwin#1660 library; 0eb0d28 (unixwin#1660 wire); -P face stayed on the C++
        PCRE2 path per DOCS/2.0-regex-engine-decision.md
- mv:   unixwin#1649; a0cfcd7 (unixwin#1773 reland that wired the 1.x retirement)
- sed:  unixwin#1635 library; f36f306 (unixwin#1690 wire)

No code changes; loc/oracle/test columns are historical measurements and
stay as recorded.
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.

1 participant