From 9e408d4bb50cb7c4e9d0a007b95f9fb9d32a16d0 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 3 Jun 2024 18:30:09 -0400 Subject: Make ELOOP an error again, except for -xtype. 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 470589cbd9ca3e73d8c01ac3a96cbc065179dcc5. Link: https://savannah.gnu.org/bugs/?19605 --- Makefile | 2 +- docs/CHANGELOG.md | 12 ++++++++++++ src/bfstd.c | 2 +- src/eval.c | 7 +++++++ tests/gnu/L_loops_continue.out | 1 - tests/gnu/ignore_readdir_race_loop.out | 1 - tests/gnu/xtype_l_loops.out | 3 +++ tests/gnu/xtype_l_loops.sh | 1 + 8 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 tests/gnu/xtype_l_loops.out create mode 100644 tests/gnu/xtype_l_loops.sh diff --git a/Makefile b/Makefile index cfefe62..e256ac7 100644 --- a/Makefile +++ b/Makefile @@ -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' >>$@ diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1d4bdcf..db978b8 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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 --- diff --git a/src/bfstd.c b/src/bfstd.c index 1c5e289..44eda7c 100644 --- a/src/bfstd.c +++ b/src/bfstd.c @@ -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 diff --git a/src/eval.c b/src/eval.c index 0495207..cef766d 100644 --- a/src/eval.c +++ b/src/eval.c @@ -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; diff --git a/tests/gnu/L_loops_continue.out b/tests/gnu/L_loops_continue.out index faf33d3..a514555 100644 --- a/tests/gnu/L_loops_continue.out +++ b/tests/gnu/L_loops_continue.out @@ -4,7 +4,6 @@ loops/deeply loops/deeply/nested loops/deeply/nested/dir loops/file -loops/loop loops/notdir loops/skip loops/skip/dir diff --git a/tests/gnu/ignore_readdir_race_loop.out b/tests/gnu/ignore_readdir_race_loop.out index faf33d3..a514555 100644 --- a/tests/gnu/ignore_readdir_race_loop.out +++ b/tests/gnu/ignore_readdir_race_loop.out @@ -4,7 +4,6 @@ loops/deeply loops/deeply/nested loops/deeply/nested/dir loops/file -loops/loop loops/notdir loops/skip loops/skip/dir diff --git a/tests/gnu/xtype_l_loops.out b/tests/gnu/xtype_l_loops.out new file mode 100644 index 0000000..fdaccab --- /dev/null +++ b/tests/gnu/xtype_l_loops.out @@ -0,0 +1,3 @@ +loops/broken +loops/loop +loops/notdir diff --git a/tests/gnu/xtype_l_loops.sh b/tests/gnu/xtype_l_loops.sh new file mode 100644 index 0000000..6893134 --- /dev/null +++ b/tests/gnu/xtype_l_loops.sh @@ -0,0 +1 @@ +bfs_diff loops -xtype l -- cgit v1.2.3