Skip to content

WIP: winx5-find — GNU -type set, -L loop detection, -printf time directives, find-owned diagnostics (#1377 #1378 #1379 #1380) - #1400

Merged
caomengxuan666 merged 14 commits into
mainfrom
fix/winx5-find
Oct 27, 2026
Merged

caomengxuan666 merged 14 commits into
mainfrom
fix/winx5-find

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Delivered by the winx5-find cluster (4 commits, one per issue, on top of the pre-rebase winx3-find tip 271dba1). Full report: cluster REPORT.md in winuxcmd-fix/clusters/winx5-find.

⚠️ STACKED / DO NOT MERGE AS-IS: winx3-find landed via PR #1388 after a rebase, so this branch's base commits are in main under different hashes. Main-session check 2026-10-26: cherry-picking onto current main — #1377 applies clean; #1378 conflicts in src/commands/find.cpp against main's rebased winx3 content; #1379/#1380 not attempted. Integrator: rebase the four commits onto main and resolve find.cpp keeping both sides' semantics.

⚠️ VERIFICATION PENDING: the cluster's post-fix harness verification never completed (build-slot starvation + repeated VM replacements; see REPORT). Pre-fix behaviour was re-verified byte-identical on the winx3 harness; the four fix commits carry compile risk. After rebase, adjudicate via Windows CI unit tests (9 new issue_137x pins in tests/unit/find/find_unit_test.cpp) + differential cases 55/56.

i18n: the cluster's i18n sync commit (f3b8d98, sibling clone, NOT pushed) bumps VERSION 0.6.20→0.6.21, which is stale — 0.6.21 is already tagged (i18n PR #10) and 0.6.22 is in i18n PR #12. Re-bump past 0.6.22 at integration and run i18n_batch.py extract/validate first.

Oracle correction recorded in REPORT: GNU findutils 4.9.0 rejects -type u (issue text said it accepts); the fix follows the oracle. #1380's shape changed after #1317 landed (start point silently swallowed); fix and tests target the current shape.

caomengxuan666 and others added 14 commits October 26, 2026 00:02
…ersal roots (#1317)

GNU rejects every '=value' form (e.g. -maxdepth=1) with 'unknown
predicate', and treats a leading '--' as end-of-option scanning. The
root/expression pre-scan only recognized exact option spellings, so it
swallowed '-maxdepth=1' as a second start point (listing '.' then failing
on the bogus root) and treated '--' itself as a root. Route any dash-led
token that is not a leading global option to the expression parser
(skipping '--' only before the first root; a lone '-' stays a root), and
report unrecognized predicates by name, matching GNU's diagnostic.
…1312)

GNU treats -mindepth 2 -maxdepth 1 as valid and matching nothing (empty
output, exit 0). Only negative depths remain an error.
…ls fields (#1309)

-ls, -fls and -quit are actions, so their presence must suppress the
default -print like -print/-printf/-exec do; previously every -ls line
was followed by a bare-path line and -quit printed the entry. Also
rewrite the -ls/-fls line to GNU's 'ls -dils' shape (inode, 1K blocks,
mode, links, owner, group, size, date, path) with the 6-month date rule
('%b %e %H:%M' vs '%b %e %Y'); fields are single-space separated. The
existing find_quit_stops_after_first_match test pinned the old buggy
output and is updated to GNU behavior (empty stdout; the -print -quit
case keeps covering the traversal-stop property).
)

GNU sizes every type: symlinks by target-path length (lstat), regular
files and directories by stat size, fifos/sockets as 0 units; under -L a
symlink resolves to its target's size, with a dangling link falling back
to the link itself. Replaces the regular-file gate with a follow-aware
size source used by both the expression and the filter evaluation paths.
Directory sizes stay platform-dependent (0 where the platform reports
none); fifo/socket cases are verified under Wine only, as the repo
suite cannot create fifos on Windows.
A u/g/o letter in permission position copies the source class's current
rwx bits (from the mode accumulated so far, starting at 0) into the
target class, for all three operators; '=' still clears the target's
bits first. Previously the class-letter parser admitted only rwxXst and
rejected every copy clause. Tests use only modes the Windows permission
mapping can produce (0755/0644/0555); the 0777-symlink shape is covered
by the same code path and the GNU probe, as Wine does not expose Linux
symlinks as reparse points.
GNU resolves a non-numeric -user/-group name at parse time: an unknown
name is an error (exit 1), not a never-matching predicate. Numeric specs
pass without a lookup, matching the fallback in win32_account_matches.
Diagnostic wording matches GNU verbatim ('... is not the name of a known
user' / '... an existing group'). No committed positive-name test: name
resolution is platform-dependent (e.g. 'root' resolves under Wine but not
on real Windows); the numeric case covers the pass path.
…ive -newermt (#1311)

Replace the floor/trunc age model (which clamped future timestamps to 0
and rejected fractions) with GNU's two window families over the age in
whole seconds: MIN family (amin/cmin/mmin, -used on the atime-ctime gap)
exact (v-1)u <= age < vu, +v age > vu, -v age < vu; DAY family
(atime/ctime/mtime) exact vu <= age < (v+1)u, +v age >= (v+1)u, -v age <
vu. Time numerics now parse as doubles (0.5, .5, 1., 1e3 accepted;
full-consumption check rejects 1e/hex/inf/nan). -daystart uses
calendar-day differences for the DAY family (DST-safe via llround),
preserving the existing -daystart -mtime 0 expectation; the MIN family
now ignores -daystart, matching GNU. -used compares the gap in raw
ticks for the negativity test: a freshly created file can carry atime a
few hundred microseconds before ctime, and GNU (timespec-precise)
treats any negative gap as never-matching. -newermt gains a get_date
subset: now/today/tomorrow/yesterday as now-offsets, last/next unit,
<n>|a unit[s] ago, and month-name dates; 'an' is rejected as GNU
rejects it, as are midnight/noon.
… position (#1315)

run_child no longer overloads 127 for spawn failures: it returns an
optional status with the failure reason (resolve status mapped to
No such file or directory / Permission denied / Not a directory,
CreateProcessW failures via FormatMessage), so the caller can print
GNU's per-file diagnostic (find: '<cmd>': <reason>) while keeping the
exit status unchanged for the \; form (GNU exec.c:388-392) and setting
it for the + form (exec.c:397-399). A child exiting non-zero still
produces no spawn diagnostic. {} is now substituted in the command
position as well as in arguments, and a non-trailing {} in a + form
expands to the full target list (the parser already pops the trailing
{}). Left unhandled and documented: aggregate command-position {} with
+ (one program name cannot be a batch) and -ok prompt display.
…#1377)

-type/-xtype rejected every letter except f/d/l/p, so scripts using
b (block device), c (character device) or s (socket) failed before
find even started.  Validate the argument the GNU way
(findutils parser.c, probed against findutils 4.9.0): a comma-
separated list of letters from bcdpfls, 'D' rejected with the
Solaris doors diagnostic, concatenated letters rejected with
'Must separate multiple arguments to -type using: ',,', and empty
or trailing-comma arguments diagnosed by name.  Matching gains the
b/c/s letters via std::filesystem file types; a type that cannot
occur simply matches nothing, as in GNU.

Regression: issue_1377_type_accepts_b_c_s_letters,
issue_1377_type_comma_list_and_gnu_diagnostics, differential case
55-find-type-letters.
#1378)

A symlink cycle (root/d/loop -> ..) was traversed level after level
until the path stopped fitting: 51 lines of ever-deepening paths and
a 'No such file or directory' error.  GNU reports the loop once and
stops.  Track the (volume, file-index) identity of every directory
on the current traversal path - with a followed identity (the
existing win32_file_identity pins the reparse point itself, whose
index can never alias an ancestor) - in all three traversal shapes,
and on a hit print GNU's diagnostic, set the error status and skip
both descent and evaluation of the entry:
  find: File system loop detected; '<path>' is part of the same
  file system loop as '<ancestor>'.

Regression: issue_1378_L_reports_filesystem_loop_instead_of_expanding_it,
differential case 56-find-L-loop.
…lag semantics, exact %X@ (#1379)

Five measured divergences from GNU find (findutils 4.9.0):
1. %a/%c/%t were missing (printed the bare letter + warning).  New
   win32_file_time_ctime() renders the access/change/modification
   time in ctime layout with the ten-digit fraction before the year.
2. Unknown directives dropped the '%'.  GNU echoes the whole
   directive verbatim ('%Q', '%5Q'); the field spec is not applied.
3. The 0 flag zero-padded strings ('%05p' -> '00./f').  GNU honors
   0 only for %d/%m; sign flags '+'/' ' only for %d; precision
   zero-extends %d/%m and truncates strings.  PrintfPieceKind now
   classifies each conversion for apply_printf_field_spec().
4. '+' was dropped ('%+5d' printed four spaces + digit).
5. %T@ carried sub-microsecond jitter (1599999999.999999400 then
   ...500 for a file pinned to 1600000000): it converted
   std::filesystem clock values by sampling two clocks.  All %X@
   directives now render the exact FILETIME ticks with ten
   fractional digits via format_epoch_seconds().

The anti-GNU pins for faces 2/4-era behavior are flipped: the test
helpers render ten digits and [%08f] expects space padding.

Regression: issue_1379_printf_ctime_directives,
issue_1379_printf_unknown_directive_keeps_percent,
issue_1379_printf_flag_semantics_per_conversion,
issue_1379_printf_epoch_is_exact_and_deterministic.
…#1380)

Unknown predicates were answered by the shared option parser
('--zzz' -> "unrecognized option", '-bogus' -> "invalid option --
'b'" with the predicate bundled and its first letter blamed), and
the leading global options -D / -ignore_readdir_race fell out of
parse_roots entirely: after the #1317 fix they no longer error as
missing operands, but the start point after them is never collected
and the walk silently runs on '.'.

- option_policy_for_command("find"): allow_long_options = false +
  allow_unknown_short_options_as_positionals = true (the mechanism
  printf/expr/test already use).  Unknown dash tokens now reach
  find's own expression parser, which reports
  "unknown predicate `<tok>'".  Registered predicates are
  unaffected: multi-char single-dash names match exactly first, and
  tokens glued to a one-letter value option (-O2, -Dtree) still
  parse as that option.
- parse_roots() skips -nowarn/-warn/-ignore_readdir_race/
  -noignore_readdir_race and -D/--debug + value before the first
  root, mirroring expression_start_index.
- build_config() honors --debug (the -D alias) from raw_args for
  debug_enabled/debug_category.  --debug stays a working alias
  (WinuxCmd's documented extension); GNU's unknown-predicate answer
  was the other acceptable resolution - the defect was the
  missing-operand diagnostic, which is gone.

Regression: issue_1380_unknown_predicates_are_answered_by_find,
issue_1380_global_options_reach_their_start_point (exact-output
assertions with a same-named top-level file as wrong-root
discriminator).
# Conflicts:
#	src/commands/find.cpp
#	tests/unit/find/find_unit_test.cpp
…1379)

- Drop the three leftover closing braces the find.cpp merge left at
  the scan_one_root seam so the file compiles again.
- The pre-existing unknown-directive pin expected the '%' to be
  dropped; GNU echoes the directive verbatim with '%' included —
  flip the pin to the GNU expectation (issue #1379, face 2).
- The new flag-semantics pin over-padded %05p by one space: "./f"
  pads to the stated width 5 with two spaces, matching the
  probe-verified GNU oracle recorded in the issue.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 27, 2026 05:43
@caomengxuan666

Copy link
Copy Markdown
Member Author

Verified post-merge (merge 4b585a0 + fixup bd65ee3): MSVC Debug build green; full ctest 3237 — the 11 residuals are exactly the environment-bound baseline set on clean origin/main (3x issue_1288 LongPathsEnabled=0, find.issue_1309_ls, 7x xargs CONIN$); find.* is 152/153 with only that baseline failure left.

Merge resolution: scan_one_root keeps this branch's #1378 ancestor-chain loop detection AND main's non-throwing it.increment(ec) advance (continue paths restructured so the manual increment always runs); find_unit_test seam rebalanced.

Two test pins corrected to the probe-verified GNU oracle in #1379: the pre-existing unknown-directive pin expected the '%' to be dropped, but GNU echoes unknown directives verbatim ('%' included — implementation already correct, pin flipped and renamed to ..._keeps_percent); the new flag-semantics pin over-padded %05p by one space ("./f" pads to the stated width 5 → " ./f", not " ./f").

i18n: en adds 3 filesystem-loop keys (+printf option description gains %a/%c/%t placeholders), drops the stale '-type currently supports only f,d,l,p' key. Synced on winuxcmd-i18n sync/winx5-find-i18n (zh-CN keys added, VERSION 0.6.27).

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