1 From 0afb2efada7e435ae18ef7d3db0758464189f44f Mon Sep 17 00:00:00 2001
2 From: Bernhard Voelker <mail@bernhard-voelker.de>
3 Date: Tue, 30 Jan 2018 23:30:09 +0100
4 Subject: find: make -delete honour the -ignore_readdir_race option
6 * find/pred.c (pred_delete): Return true when the -ignore_readdir_race
7 option is active and unlinkat() came back with ENOENT.
8 * doc/find.texi (Option -ignore_readdir_race): Document the change.
9 (Action -delete): Likewise.
10 * find/find.1: Likewise.
11 * NEWS (Bug Fixes): Mention the fix.
13 For now, it seems a bit hard to add a proper test for this,
14 so the following shell snippet demonstrates the race:
16 $ seq 10 | xargs touch
17 $ env time -f 'find exit status: %x\nfind time: %e' \
18 find -ignore_readdir_race -type f \
20 -exec sh -c 'sleep $(basename {})' \; \
21 -printf 'find deleted: %p\n' \
24 seq 10 | xargs rm -fv; \
27 Reported by Alexander Golubev in
28 https://savannah.gnu.org/bugs/?52981
30 Upstream-Status: Backport
31 Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com>
34 doc/find.texi | 15 ++++++++++++++-
35 find/find.1 | 22 ++++++++++++++++++++++
36 find/pred.c | 6 ++++++
37 4 files changed, 46 insertions(+), 1 deletion(-)
39 diff --git a/NEWS b/NEWS
40 index 88cf17d..9809bf4 100644
47 +#52981: find: the '-delete' action no longer complains about disappeared files
48 + when the '-ignore_readdir_race' option is given, too. That action will
49 + also returns true in such a case now.
51 Applied patch #8688: Spelling fixes.
53 * Major changes in release 4.5.18, 2015-12-27
54 diff --git a/doc/find.texi b/doc/find.texi
55 index 3580be7..0089193 100644
58 @@ -1418,7 +1418,15 @@ gives a significant increase in search speed.
59 If a file disappears after its name has been read from a directory but
60 before @code{find} gets around to examining the file with @code{stat},
61 don't issue an error message. If you don't specify this option, an
62 -error message will be issued. This option can be useful in system
63 +error message will be issued.
65 +Furthermore, @code{find} with the @samp{-ignore_readdir_race} option
66 +will ignore errors of the @samp{-delete} action in the case the file
67 +has disappeared since the parent directory was read: it will not output
68 +an error diagnostic, and the return code of the @samp{-delete} action
71 +This option can be useful in system
72 scripts (cron scripts, for example) that examine areas of the
73 filesystem that change frequently (mail queues, temporary directories,
74 and so forth), because this scenario is common for those sorts of
75 @@ -2779,6 +2787,11 @@ explicitly.
77 If @samp{-delete} fails, @code{find}'s exit status will be nonzero
78 (when it eventually exits).
80 +Together with the @samp{-ignore_readdir_race} option, @code{find} will
81 +ignore errors of the @samp{-delete} action in the case the file has disappeared
82 +since the parent directory was read: it will not output an error diagnostic, and
83 +the return code of the @samp{-delete} action will be true.
87 diff --git a/find/find.1 b/find/find.1
88 index 0437cd8..0d44c37 100644
91 @@ -479,6 +479,17 @@ this option on and part of it with this option off
92 (if you need to do that, you will need to issue two \fBfind\fR commands
93 instead, one with the option and one without it).
98 +.B \-ignore_readdir_race
99 +option will ignore errors of the
101 +action in the case the file has disappeared since the parent directory was read:
102 +it will not output an error diagnostic, and the return code of the
104 +action will be true.
106 .IP "\-maxdepth \fIlevels\fR"
107 Descend at most \fIlevels\fR (a non-negative integer) levels of
108 directories below the starting-points.
109 @@ -1030,6 +1041,17 @@ and
114 +.B \-ignore_readdir_race
117 +will ignore errors of the
119 +action in the case the file has disappeared since the parent directory was
120 +read: it will not output an error diagnostic, and the return code of the
122 +action will be true.
124 .IP "\-exec \fIcommand\fR ;"
125 Execute \fIcommand\fR; true if 0 status is returned. All following
127 diff --git a/find/pred.c b/find/pred.c
128 index 7e2a7bd..af3bacb 100644
131 @@ -324,6 +324,12 @@ pred_delete (const char *pathname, struct stat *stat_buf, struct predicate *pred
135 + if (ENOENT == errno && options.ignore_readdir_race)
137 + /* Ignore unlink() error for vanished files. */
143 if ((flags & AT_REMOVEDIR) == 0)