Skip to content

Commit

Permalink
Make ELOOP an error again, except for -xtype.
Browse files Browse the repository at this point in the history
POSIX requires an error if (for example) -L encounters a symlink loop.
The GNU find change was restricted to -xtype, so add a manual ELOOP test
to eval_xtype() for compatibility.

This reverts commit 470589c.

Link: https://savannah.gnu.org/bugs/?19605
  • Loading branch information
tavianator committed Jun 3, 2024
1 parent 6e4c389 commit 9e408d4
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ gen/version.c.new::
elif test -e src/../.git && command -v git >/dev/null 2>&1; then \
git -C src/.. describe --always --dirty; \
else \
echo "3.3"; \
echo "3.3.1"; \
fi | tr -d '\n' >>$@
@printf '";\n' >>$@

Expand Down
12 changes: 12 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
3.*
===

3.3.1
-----

**June 3, 2024**

### Bug fixes

- Reduced the scope of the symbolic link loop change in version 3.3.
`-xtype l` remains true for symbolic link loops, matching a change in GNU findutils 4.10.0.
However, `-L` will report an error, just like `bfs` prior to 3.3 and other `find` implementations, as required by POSIX.


3.3
---

Expand Down
2 changes: 1 addition & 1 deletion src/bfstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool error_is_like(int error, int category) {

switch (category) {
case ENOENT:
return error == ENOTDIR || error == ELOOP;
return error == ENOTDIR;

case ENOSYS:
// https://github.com/opencontainers/runc/issues/2151
Expand Down
7 changes: 7 additions & 0 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,13 @@ bool eval_xtype(const struct bfs_expr *expr, struct bfs_eval *state) {
const struct BFTW *ftwbuf = state->ftwbuf;
enum bfs_stat_flags flags = ftwbuf->stat_flags ^ (BFS_STAT_NOFOLLOW | BFS_STAT_TRYFOLLOW);
enum bfs_type type = bftw_type(ftwbuf, flags);

// GNU find treats ELOOP as a broken symbolic link for -xtype l
// (but not -L -type l)
if ((flags & BFS_STAT_TRYFOLLOW) && type == BFS_ERROR && errno == ELOOP) {
type = BFS_LNK;
}

if (type == BFS_ERROR) {
eval_report_error(state);
return false;
Expand Down
1 change: 0 additions & 1 deletion tests/gnu/L_loops_continue.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ loops/deeply
loops/deeply/nested
loops/deeply/nested/dir
loops/file
loops/loop
loops/notdir
loops/skip
loops/skip/dir
Expand Down
1 change: 0 additions & 1 deletion tests/gnu/ignore_readdir_race_loop.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ loops/deeply
loops/deeply/nested
loops/deeply/nested/dir
loops/file
loops/loop
loops/notdir
loops/skip
loops/skip/dir
Expand Down
3 changes: 3 additions & 0 deletions tests/gnu/xtype_l_loops.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
loops/broken
loops/loop
loops/notdir
1 change: 1 addition & 0 deletions tests/gnu/xtype_l_loops.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bfs_diff loops -xtype l

0 comments on commit 9e408d4

Please sign in to comment.