Skip to content

Commit 9e408d4

Browse files
committed
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 470589c. Link: https://savannah.gnu.org/bugs/?19605
1 parent 6e4c389 commit 9e408d4

8 files changed

+25
-4
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ gen/version.c.new::
7474
elif test -e src/../.git && command -v git >/dev/null 2>&1; then \
7575
git -C src/.. describe --always --dirty; \
7676
else \
77-
echo "3.3"; \
77+
echo "3.3.1"; \
7878
fi | tr -d '\n' >>$@
7979
@printf '";\n' >>$@
8080

docs/CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
3.*
22
===
33

4+
3.3.1
5+
-----
6+
7+
**June 3, 2024**
8+
9+
### Bug fixes
10+
11+
- Reduced the scope of the symbolic link loop change in version 3.3.
12+
`-xtype l` remains true for symbolic link loops, matching a change in GNU findutils 4.10.0.
13+
However, `-L` will report an error, just like `bfs` prior to 3.3 and other `find` implementations, as required by POSIX.
14+
15+
416
3.3
517
---
618

src/bfstd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool error_is_like(int error, int category) {
4444

4545
switch (category) {
4646
case ENOENT:
47-
return error == ENOTDIR || error == ELOOP;
47+
return error == ENOTDIR;
4848

4949
case ENOSYS:
5050
// https://github.com/opencontainers/runc/issues/2151

src/eval.c

+7
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,13 @@ bool eval_xtype(const struct bfs_expr *expr, struct bfs_eval *state) {
999999
const struct BFTW *ftwbuf = state->ftwbuf;
10001000
enum bfs_stat_flags flags = ftwbuf->stat_flags ^ (BFS_STAT_NOFOLLOW | BFS_STAT_TRYFOLLOW);
10011001
enum bfs_type type = bftw_type(ftwbuf, flags);
1002+
1003+
// GNU find treats ELOOP as a broken symbolic link for -xtype l
1004+
// (but not -L -type l)
1005+
if ((flags & BFS_STAT_TRYFOLLOW) && type == BFS_ERROR && errno == ELOOP) {
1006+
type = BFS_LNK;
1007+
}
1008+
10021009
if (type == BFS_ERROR) {
10031010
eval_report_error(state);
10041011
return false;

tests/gnu/L_loops_continue.out

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ loops/deeply
44
loops/deeply/nested
55
loops/deeply/nested/dir
66
loops/file
7-
loops/loop
87
loops/notdir
98
loops/skip
109
loops/skip/dir

tests/gnu/ignore_readdir_race_loop.out

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ loops/deeply
44
loops/deeply/nested
55
loops/deeply/nested/dir
66
loops/file
7-
loops/loop
87
loops/notdir
98
loops/skip
109
loops/skip/dir

tests/gnu/xtype_l_loops.out

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
loops/broken
2+
loops/loop
3+
loops/notdir

tests/gnu/xtype_l_loops.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bfs_diff loops -xtype l

0 commit comments

Comments
 (0)