Commit Graph

222 Commits

Author SHA1 Message Date
vip892766gma b07b27d13f chore: improve findutils maintenance path (#687) 2026-06-04 21:28:34 +02:00
Sylvestre Ledru 9a1e379a9d fix: avoid panic on -fprintf with missing arguments (#698)
Fixes #696
2026-06-05 02:41:58 +08:00
Jesse Rosenstock 5269e233a6 find: implement -ok and -okdir (#650)
-ok is like -exec ... ; but prompts the user on stderr before each
invocation and only runs the command if the response is affirmative
(starts with 'y' or 'Y').  -okdir is the corresponding -execdir variant.
Only the ';' terminator is accepted: POSIX does not define -ok ... + and
GNU find rejects it.

Response source: GNU find reads from /dev/tty so that the user's answer
always comes from the real terminal even when stdin is occupied (e.g.
`find -files0-from - -ok rm {} \;` reads paths from stdin, so responses
cannot also come from there).  /dev/tty is the POSIX name for a
process's controlling terminal and exists on all Unix-like systems.  We
open /dev/tty only when stdin is itself a terminal
(std::io::stdin().is_terminal() == true).  When stdin is a pipe or file,
we read from stdin directly — matching BSD find and making scripted use
(and integration tests via pipe_in()) work naturally without any special
environment variable.  On Windows, or when /dev/tty cannot be opened, we
likewise fall back to stdin.

Implementation: rather than a separate OkMatcher that duplicated
SingleExecMatcher's fields, constructor, and exec logic, the interactive
prompt is folded into SingleExecMatcher behind an `interactive: bool`
field.  `SingleExecMatcher::new_interactive()` constructs the -ok/-okdir
variant; `matches()` adds a guarded block that builds a GNU-find-style
prompt ("< executable arg... >? ") and calls `matcher_io.confirm()`
before executing.  If the user declines, the expression is false and the
command is not run.  This keeps the arg-parsing, path resolution,
current_dir logic, and error handling in one place so bug fixes apply to
both -exec and -ok.

Dependencies::confirm() trait method: abstracts prompt+read so matchers
remain testable without a real terminal; FakeDependencies uses a
VecDeque of preset responses.

Tests:
- Unit tests (exec_unit_tests.rs): confirmed executes command, declined
  skips command and returns false, confirmed but command fails returns
  false, -okdir runs in parent dir
- Parser unit tests (matchers/mod.rs): missing-arg errors, missing
  semicolon, correct parse, confirm/decline via FakeDependencies
- Integration tests (test_find.rs): pipe_in() makes stdin a pipe so
  is_terminal() returns false and responses are read from the pipe;
  "y"/"Y"/"yes"/" y" run command, "n" and empty response skip command,
  -okdir runs in parent dir, prompt format verified, missing-semicolon
  error

Closes https://github.com/uutils/findutils/issues/8.
2026-06-04 20:31:54 +02:00
Kevin Burke 69a20eb6df xargs: accept hyphenated -I and -E values
GNU xargs treats the arguments to -I, -E, and -e as values even when
they begin with a hyphen. Clap was parsing those strings as options
instead, so invocations like 'xargs -I -_' failed before xargs could
process input.

Allow hyphen-leading values for those options and add regression
coverage for replacement and EOF markers that start with '-'.
2026-05-05 16:26:23 +02:00
Daniel Hofstetter 111eec1b6c find: fix warnings from filter_next lint (#604) 2025-12-11 19:41:23 -03:00
Brian Pane c5c5a16700 Merge pull request #603 from brian-pane/eof
Ignore -E/-e flag when a delimiter is specified
2025-12-07 11:54:27 +01:00
Brian Pane dfc460a627 xargs: add support for -l option 2025-11-20 20:11:47 +00:00
Brian Pane 573b9b7788 xargs: add support for -E option (#593)
* xargs: add support for -E option

* Additional test coverage for xargs -E

* Simplify EofArgumentReader and test its error pass-through
2025-11-19 09:33:14 +01:00
Daniel Hofstetter df2d84dd69 clippy: fix warning from derivable_impls lint 2025-10-31 09:38:20 +01:00
Sylvestre Ledru e5f7dae2ae Merge pull request #532 from tavianator/fstype-stacked
find: Fix -fstype with stacked mounts
2025-04-24 21:18:48 +02:00
cryptodarth 3f026bfe6b Merge pull request #534 from Crypto-Darth/error-msgs
change "Error:" to "find:" + Testcase fix
2025-04-24 20:26:59 +02:00
cryptodarth a571de6812 Implement : Chained Type matcher arguments (#527)
* code dump

* fix : new checks + working stage

* minor fixes + duplicates check

* fix : add check for incorrect chained commands

* add : Chained Argument matching for -xtype

* add: test

* cargo fmt

* Add : more tests + old test fix

* refactor : move common code to function

* fix : convert match to if/else

* Improve : Testcase for xtype

* cargo clippy fix

* update : testcase

* fix : error handling

* fix : use single type

* add: basic tests on binary level

* Add : -xtype tests

* refactor : use single type without Option<>

* fix : use better search logic

* refactor : use HashSet<> instead of Vec<>

* remove : unnecessary hashmap usage

* Update src/find/matchers/type_matcher.rs

Co-authored-by: Tavian Barnes <tavianator@tavianator.com>

* change: variable name

* remove: type and replace with HashSet<FileType>

* remove: trimming

---------

Co-authored-by: Tavian Barnes <tavianator@tavianator.com>
2025-04-24 20:17:39 +02:00
Sylvestre Ledru cacb1c10bd Merge pull request #529 from KartikDua1504/fix-blocks
Fix: Use div_ceil with proper blocks computation
2025-04-10 11:23:03 -04:00
Tavian Barnes cd8790239f find: Fix -fstype with stacked mounts
If you stack two mounts on top of each other, e.g.

    # mount -t ext4 /dev/sdX /mnt
    # mount -t f2fs /dev/sdY /mnt

then read_fs_list() will return two entries for that mount point.  The
later one is the one with the correct type, since the later mount is on
top of the earlier one.
2025-04-10 09:52:26 -04:00
Kartik Dua fa4399bdbe Formatted Document 2025-04-08 01:40:22 +05:30
Kartik Dua 04a92a8fb3 Fix: Use div_ceil with proper blocks computation
Fixes: ##523
2025-04-07 21:51:13 +05:30
Tavian Barnes a61993b705 find: Allow comparable values with signs
find -uid -+10 means "UID less than +10".
2025-04-05 09:57:10 +02:00
Tavian Barnes de42f9bd83 find: Implement -uid [-+]N, -gid [-+]N
GNU find's -uid/-gid matchers take a comparable value.
2025-04-04 09:51:19 +02:00
Tavian Barnes 6d264dbbcf find: Allow -user UID / -group GID
POSIX says

> -user uname
>   The primary shall evaluate as true if the file belongs to the user
>   uname. If uname is a decimal integer and the getpwnam() (or
>   equivalent) function does not return a valid user name, uname shall
>   be interpreted as a user ID.

and similarly for -group.

Link: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/find.html
2025-04-04 09:51:19 +02:00
Daniel Hofstetter 5cb273eecb clippy: fix error from manual_div_ceil lint 2025-04-04 09:21:12 +02:00
Daniel Hofstetter 55021afb69 clippy: fix errors from double_ended_iterator_last
lint
2025-04-04 09:21:12 +02:00
Tavian Barnes 0429507f15 tests: Make -exec {} + tests deterministic
These tests failed on my system because directory entries were returned
in a different order, causing an output mismatch.  Add --sort to the
testing_commandline to make the output deterministic.
2025-04-02 22:11:27 -04:00
milkory 5235d78291 find: Implement exec[dir] + (#515)
* add argmax dependency

* implement finished and finished_dir callback

* implement multi exec matcher

* fix finished_dir not working correctly

* add more test for multi exec matcher

* fix execdir multi in current directory not working

* add more test for parsing multi exec

* set exit code when exec + failed

* fix clippy warnings

* prevent multi exec panics on long paths

---------

Co-authored-by: hanbings <hanbings@hanbings.io>
2025-04-02 21:04:48 +08:00
cryptodarth 1a40442f20 Merge pull request #509 from Crypto-Darth/main
Implement : -files0-from (#378)
2025-04-02 20:47:51 +08:00
hanbings 9fdfb1ee08 Run cargo clippy and cargo fmt. 2025-03-29 15:58:41 +08:00